diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e70085e --- /dev/null +++ b/Makefile @@ -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 + diff --git a/README.md b/README.md index 0352d4f..8479bf2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # rfc2gemini -Converts the index of RFCs to gemtext (text/gemini), to be served via Gemini. \ No newline at end of file +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) +``` + diff --git a/rfc-index2gemini.py b/rfc-index2gemini.py new file mode 100755 index 0000000..eff3da1 --- /dev/null +++ b/rfc-index2gemini.py @@ -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(" 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() +