diff --git a/leech.py b/leech.py index c0d2572..5f26ded 100644 --- a/leech.py +++ b/leech.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import argparse import importlib import os @@ -20,7 +21,7 @@ html_template = ''' ''' -def leech(url): +def leech(url, filename=None): # we have: a page, which could be absolutely any part of a story, or not a story at all # check a bunch of things which are completely ff.n specific, to get text from it site = _get_site(url) @@ -38,7 +39,9 @@ def leech(url): for i, chapter in enumerate(story['chapters']): html.append((chapter[0], 'chapter%d.html' % (i+1), html_template.format(title=chapter[0], text=chapter[1]))) - epub.make_epub(story['title'] + '.epub', html, metadata) + filename = filename or story['title'] + '.epub' + + epub.make_epub(filename, html, metadata) _sites = [] @@ -58,5 +61,10 @@ def _load_sites(): if __name__ == '__main__': _load_sites() - leech('https://www.fanfiction.net/s/4109686/3/Taking-Sights') + parser = argparse.ArgumentParser() + parser.add_argument('url', help="url of a story to fetch") + parser.add_argument('--filename', help="output filename (the title is used if this isn't provided)") + args = parser.parse_args() + + leech(args.url, filename=args.filename) pass