diff options
-rw-r--r-- | gemfeed.py | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -1,3 +1,4 @@ +import argparse import datetime import glob import os.path @@ -31,28 +32,45 @@ def populate_entry_from_file(filename, base_url, entry): title = filename entry.title(title) -def main(base_url="gemini://gemini.circumlunar.space/"): +def main(): + + # Parse arguments + parser = argparse.ArgumentParser(description='Generate an Atom feed for Gemini content.') + parser.add_argument('-b', '--base', dest='base_url', type=str, + required=True, help='base URL for feed and entries') + parser.add_argument('-o', '--output', dest='output', type=str, + default="atom.xml", help='output filename') + parser.add_argument('-t', '--title', dest='title', type=str, + default="A Gemini feed", help='feed title') + args = parser.parse_args() + + # Normalise base URL, quick and dirty + if not args.base_url.startswith("gemini://"): + args.base_url = "gemini://" + args.base_url + if not args.base_url.endswith("/"): + args.base_url = args.base_url + "/" # Setup feed feed = FeedGenerator() - feed.id(base_url) - feed.title('A Gemini feed.') - feed.link(href=base_url, rel='alternate') - feed.link(href=base_url + "atom.xml", rel='self') + feed.id(args.base_url) + feed.title(args.title) + feed.link(href=args.base_url, rel='alternate') + feed.link(href=args.base_url + "atom.xml", rel='self') # Add one entry per .gmi file files = find_files() latest_update = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc) for filename in files: entry = feed.add_entry() - populate_entry_from_file(filename, base_url, entry) + populate_entry_from_file(filename, args.base_url, entry) print("Adding {} with title '{}'...".format(filename, entry.title())) if entry.updated() > latest_update: latest_update = entry.updated() feed.updated(latest_update) # Write file - feed.atom_file('atom.xml', pretty=True) + feed.atom_file(args.output, pretty=True) + print("Wrote Atom feed to {}.".format(args.output)) if __name__ == "__main__": main() |