1 from itertools
import islice
, chain
, imap
as map
2 from optparse
import make_option
5 from django
.core
.management
.base
import BaseCommand
7 from mygpo
.core
.models
import Podcast
, PodcastGroup
8 from mygpo
.directory
.toplist
import PodcastToplist
9 from mygpo
.db
.couchdb
.podcast
import podcast_by_id
, podcast_for_url
, \
10 random_podcasts
, podcasts_by_last_update
, podcasts_need_update
13 class PodcastCommand(BaseCommand
):
14 """ command that operates on a list of podcasts specified by parameters """
16 option_list
= BaseCommand
.option_list
+ (
17 make_option('--toplist', action
='store_true', dest
='toplist',
18 default
=False, help="Update all entries from the Toplist."),
20 make_option('--update-new', action
='store_true', dest
='new',
21 default
=False, help="Update all podcasts with new Episodes"),
23 make_option('--max', action
='store', dest
='max', type='int',
24 default
=0, help="Set how many feeds should be updated at maximum"),
26 make_option('--random', action
='store_true', dest
='random',
27 default
=False, help="Update random podcasts, best used with --max"),
32 def get_podcasts(self
, *args
, **options
):
33 return chain
.from_iterable(self
._get
_podcasts
(*args
, **options
))
36 def _get_podcasts(self
, *args
, **options
):
37 if options
.get('toplist'):
38 yield (p
.url
for p
in self
.get_toplist())
40 if options
.get('new'):
41 podcasts
= list(podcasts_need_update())
42 random
.shuffle(podcasts
)
43 yield (p
.url
for p
in podcasts
)
45 if options
.get('random'):
46 yield (p
.url
for p
in random_podcasts())
52 if not args
and not options
.get('toplist') and not options
.get('new') \
53 and not options
.get('random'):
54 yield (p
.url
for p
in podcasts_by_last_update())
57 def get_toplist(self
):
58 toplist
= PodcastToplist()
59 for oldindex
, obj
in toplist
[:100]:
60 if isinstance(obj
, Podcast
):
62 elif isinstance(obj
, PodcastGroup
):
63 for p
in obj
.podcasts
: