First code import

This commit is contained in:
Stephane Bortzmeyer 2021-03-27 16:45:34 +00:00
parent ffa86df80f
commit a1171cfa21
3 changed files with 59 additions and 1 deletions

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
DEST=/var/gemini/rfc-mirror
all: rfc-index
rfc-index:
rsync -avz --delete --exclude=\*.gmi ftp.rfc-editor.org::rfcs-text-only ${DEST}
./rfc-index2gemini.py && mv ${DEST}/rfc-index.gmi.tmp ${DEST}/rfc-index.gmi

View File

@ -1,3 +1,14 @@
# rfc2gemini
Converts the index of RFCs to gemtext (text/gemini), to be served via Gemini.
Converts the index of [RFCs](https://www.rfc-editor.org/) to gemtext (`text/gemini`), to be served via [Gemini](https://en.wikipedia.org/wiki/Gemini_(protocol)).
## Installation
Download the program. Check that the paths in `Makefile` and `rfc-index2gemini.py` are OK for you. Then run the program periodically, for
instance through cron:
```
# RFC index
52 1,5,9,13,17,21 * * * (cd /path/to/RFC-index; make all)
```

39
rfc-index2gemini.py Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import sys
import re
import time
import xml.etree.ElementTree as ET
INPUT = "/var/gemini/rfc-mirror/rfc-index.xml"
OUTPUT = "/var/gemini/rfc-mirror/rfc-index.gmi.tmp"
tree = ET.parse(INPUT)
output = open(OUTPUT, "w")
root = tree.getroot()
rfcs = {}
for child in root:
if child.tag == "{http://www.rfc-editor.org/rfc-index}rfc-entry":
num = None
for subchild in child:
if subchild.tag == "{http://www.rfc-editor.org/rfc-index}doc-id":
match = re.match("^RFC([0-9]+)", subchild.text)
if match:
num = int(match.group(1))
rfcs[num] = {}
else:
print("<rfc-entry> without a RFC: %s" % subchild.text, file=sys.stderr)
elif subchild.tag == "{http://www.rfc-editor.org/rfc-index}title":
if num is not None:
rfcs[num]['title'] = subchild.text
print("# Index of RFCs", file=output)
print("""
This index was built on %s from the rfc-index.xml file found at rsync::ftp.rfc-editor.org::rfcs-text-only.
""" % time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(time.time())), file=output)
for rfc in sorted(rfcs.keys(), reverse=True):
print("=> /rfc-mirror/rfc%s.txt RFC %s \"%s\"" % (rfc, rfc, rfcs[rfc]['title']), file=output)
output.close()