fix feed-downloader
[mygpo.git] / mygpo / data / management / commands / feed-downloader.py
blob994e2e66c55bcb43f380b456467f84855cbd8d2e
1 from itertools import islice
2 import traceback
3 from optparse import make_option
5 from restkit.errors import RequestFailed
7 from mygpo.maintenance.management.podcastcmd import PodcastCommand
8 from mygpo.data.feeddownloader import PodcastUpdater
10 try:
11 from gevent import monkey
12 monkey.patch_all()
13 except ImportError:
14 pass
17 class Command(PodcastCommand):
19 option_list = PodcastCommand.option_list + (
20 make_option('--list-only', action='store_true', dest='list',
21 default=False, help="Don't update anything, just list podcasts "),
25 def handle(self, *args, **options):
27 queue = self.get_podcasts(*args, **options)
29 max_podcasts = options.get('max')
30 if max_podcasts:
31 queue = islice(queue, 0, max_podcasts)
33 if options.get('list'):
34 for podcast in queue:
35 print podcast
37 else:
38 print 'Updating podcasts...'
40 updater = PodcastUpdater()
41 for podcast in updater.update_queue(queue):
42 print podcast