1
from __future__ import with_statement
3
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
5
Convert web feeds to LRF files.
7
from calibre.ebooks.lrf import option_parser as lrf_option_parser
8
from calibre.ebooks.lrf.html.convert_from import process_file
9
from calibre.web.feeds.main import option_parser as feeds_option_parser
10
from calibre.web.feeds.main import run_recipe
11
from calibre.ptempfile import TemporaryDirectory
12
from calibre import sanitize_file_name, strftime
17
parser = feeds_option_parser()
18
parser.remove_option('--output-dir')
19
parser.remove_option('--lrf')
20
parser.subsume('FEEDS2DISK OPTIONS', _('Options to control the behavior of feeds2disk'))
21
lrf_parser = lrf_option_parser('')
22
lrf_parser.subsume('HTML2LRF OPTIONS', _('Options to control the behavior of html2lrf'))
23
parser.merge(lrf_parser)
26
def main(args=sys.argv, notification=None, handler=None):
27
parser = option_parser()
28
opts, args = parser.parse_args(args)
31
if len(args) != 2 and opts.feeds is None:
35
recipe_arg = args[1] if len(args) > 1 else None
37
with TemporaryDirectory('_feeds2lrf') as tdir:
38
opts.output_dir = tdir
40
recipe = run_recipe(opts, recipe_arg, parser, notification=notification, handler=handler)
42
htmlfile = os.path.join(tdir, 'index.html')
43
if not os.access(htmlfile, os.R_OK):
44
raise RuntimeError(_('Fetching of recipe failed: ')+recipe_arg)
46
lparser = lrf_option_parser('')
47
ropts = lparser.parse_args(['html2lrf']+recipe.html2lrf_options)[0]
48
parser.merge_options(ropts, opts)
51
ext = '.lrs' if opts.lrs else '.lrf'
52
fname = recipe.title + strftime(recipe.timefmt)+ext
53
opts.output = os.path.join(os.getcwd(), sanitize_file_name(fname))
54
print 'Generating LRF...'
55
process_file(htmlfile, opts)
58
if __name__ == '__main__':