f377e7c71333507e676006ef7c3a434e03266533
[mygpo.git] / mygpo / data / management / commands / feed-downloader.py
blobf377e7c71333507e676006ef7c3a434e03266533
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
16 import socket
17 socket.setdefaulttimeout(300)
20 class Command(PodcastCommand):
22 option_list = PodcastCommand.option_list + (
23 make_option('--list-only', action='store_true', dest='list',
24 default=False, help="Don't update anything, just list podcasts "),
28 def handle(self, *args, **options):
30 queue = self.get_podcasts(*args, **options)
32 max_podcasts = options.get('max')
33 if max_podcasts:
34 queue = islice(queue, 0, max_podcasts)
36 if options.get('list'):
37 for podcast in queue:
38 print podcast
40 else:
41 print 'Updating podcasts...'
43 updater = PodcastUpdater()
44 for podcast in updater.update_queue(queue):
45 print podcast