3 from __future__
import with_statement
12 from optparse
import OptionParser
14 os
.environ
['DJANGO_SETTINGS_MODULE'] = 'riffle.settings'
15 from riffle
.catcher
.models
import *
17 ##########################################################################
20 p
.add_option('-n', "--skip-download", dest
='skip_download', action
='store_true',
22 help="don't download episodes (just refresh or subscribe)")
23 p
.add_option("--skip-refresh", dest
='skip_refresh', action
='store_true',
25 help="don't refresh feeds even if some of them might have changed")
26 p
.add_option("--force-refresh", dest
='force_refresh', action
='store_true',
28 help='skip checking if feeds have changed since the last time')
29 p
.add_option('--drown', dest
='drown_date', default
=None,
30 help='mark all episodes until given date as downloaded')
31 p
.add_option("-v", "--verbose", dest
='verbose', action
='store_true', default
=False,
32 help='be verbose on console (FIXME should go to logging configuration)')
34 (conf
.opts
, conf
.args
) = p
.parse_args()
36 ##########################################################################
38 # FIXME this has to be hidden + configurable
41 format
='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
42 datefmt
='%m-%d %H:%M',
43 filename
='catcher.log',
45 console
= logging
.StreamHandler()
46 console
.setLevel(logging
.DEBUG
if conf
.opts
.verbose
else logging
.INFO
)
47 formatter
= logging
.Formatter('%(levelname)-8s %(message)s')
48 console
.setFormatter(formatter
)
49 logging
.getLogger('').addHandler(console
)
51 ##########################################################################
53 if conf
.opts
.drown_date
is not None:
54 # FIXME more convenient date parser
55 from email
.utils
import parsedate
56 level
= datetime
.fromtimestamp(time
.mktime(parsedate(conf
.opts
.drown_date
)))
57 for e
in Episode
.objects
.filter(timestamp__lt
=level
,downloaded__isnull
=True):
58 logging
.info("Drowning %s", e
)
59 e
.downloaded
= e
.timestamp
63 if len(conf
.args
) > 0:
64 feeds
= [Feed
.objects
.get_or_create(url
=url
)[0] for url
in conf
.args
]
66 feeds
= Feed
.objects
.all()
68 if not conf
.opts
.skip_refresh
:
72 if not conf
.opts
.skip_download
:
73 dlq
= Episode
.objects
.filter(downloaded__isnull
=True).order_by('timestamp')