1 from django
.core
.management
.base
import BaseCommand
2 from mygpo
.api
import models
3 from mygpo
.data
.models
import PodcastTag
4 from mygpo
.data
import delicious
5 from optparse
import make_option
9 class Command(BaseCommand
):
11 option_list
= BaseCommand
.option_list
+ (
12 make_option('--toplist', action
='store_true', dest
='toplist', default
=False, help="Update all entries from the Toplist."),
13 make_option('--max', action
='store', dest
='max', type='int', default
=-1, help="Set how many feeds should be updated at maximum"),
15 make_option('--random', action
='store_true', dest
='random', default
=False, help="Update random podcasts, best used with --max option"),
19 def handle(self
, *args
, **options
):
23 if options
.get('toplist'):
24 for e
in models
.ToplistEntry
.objects
.all().order_by('-subscriptions')[:100]:
25 fetch_queue
.append(e
.podcast
)
27 if options
.get('random'):
28 fetch_queue
= models
.Podcast
.objects
.all().order_by('?')
32 fetch_queue
.append(models
.Podcast
.objects
.get(url
=url
))
36 max = options
.get('max', -1)
38 fetch_queue
= fetch_queue
[:max]
41 if not p
or not p
.link
:
44 # we don't want to spam delicious
48 f
= urllib2
.urlopen(p
.link
)
52 tags
= delicious
.get_tags(f
.url
)
54 for tag
, count
in tags
.iteritems():
56 print ' %s' % tag
.decode('utf-8')
59 PodcastTag
.objects
.filter(tag
=tag
, podcast
=p
, source
='delicious').delete()
60 PodcastTag
.objects
.create(tag
=tag
, podcast
=p
, source
='delicious', weight
=count
)