various feed-downloader improvements
[mygpo.git] / mygpo / data / management / commands / feed-downloader.py
blobba4b3bfdc8be651a243cb9ed764a0be2c80dbd36
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 from gevent import monkey
11 monkey.patch_all()
14 class Command(PodcastCommand):
16 option_list = PodcastCommand.option_list + (
17 make_option('--list-only', action='store_true', dest='list',
18 default=False, help="Don't update anything, just list podcasts "),
22 def handle(self, *args, **options):
24 queue = self.get_podcasts(*args, **options)
26 max_podcasts = options.get('max')
27 if max_podcasts:
28 queue = islice(queue, 0, max_podcasts)
30 if options.get('list'):
31 for podcast in queue:
32 print podcast.url
34 else:
35 print 'Updating podcasts...'
37 updater = PodcastUpdater(queue)
38 updater.update()