diff --git a/requirements.txt b/requirements.txt index 5f558e4..932ebf3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ readability-lxml requests html2text toml +opml diff --git a/scripts/ompl2spiderss.py b/scripts/ompl2spiderss.py new file mode 100755 index 0000000..2576e3a --- /dev/null +++ b/scripts/ompl2spiderss.py @@ -0,0 +1,42 @@ +#/usr/bin/env python + +import argparse +import opml +import os +import sys + +# Prints elements recursively for all outlines +def print_outline(outline, category): + if len(outline) > 0: + for o in outline: + print_outline(o, os.path.join(category, outline.text)) + else: + print('[[feed]]') + print('category = \'{}\''.format(category)) + print('name = \'{}\''.format(outline.text)) + print('url = \'{}\''.format(outline.xmlUrl)) + print('') + +''' +Main +''' + +def main(): + + parser = argparse.ArgumentParser(description = 'Read an OPML file and print spiderss TOML format to stdout.') + parser.add_argument('file', help = 'OPML input file') + args = parser.parse_args() + + file = args.file + + try: + outline = opml.parse(file) + for o in outline: + print_outline(o, '') + except Exception as e: + print('ERROR: {}'.format(e)) + sys.exit(1) + + +if __name__ == '__main__': + main()