Run 2to3-3.4
[mygpo.git] / mygpo / data / management / commands / tag-downloader.py
blob9a83efac69b7520ef74fbcbb2eba629e2e9fb698
1 import time
2 import urllib.request, urllib.error, urllib.parse
3 from optparse import make_option
5 from mygpo.data import delicious
6 from mygpo.maintenance.management.podcastcmd import PodcastCommand
9 SOURCE = 'delicious'
11 class Command(PodcastCommand):
12 """
13 Adds tags from the webservice delicious.com to podcasts
15 Podcasts are specified either by URL or the --toplist and --random
16 parameter. The delicious webservice is queried for the podcasts' websites.
17 The returned tags are added to the podcasts for the 'delicious' source.
18 """
20 def handle(self, *args, **options):
22 fetch_queue = self.get_podcasts()
24 for p in fetch_queue:
25 if not p or not p.link:
26 continue
28 # we don't want to spam delicious
29 time.sleep(1)
31 try:
32 f = urllib.request.urlopen(p.link)
33 except urllib.error.HTTPError:
34 continue
36 tags = delicious.get_tags(f.url)
38 self.update(podcast=p, tags=tags)
41 def update(self, podcast, tags):
42 podcast.tags[SOURCE] = tags
43 podcast.save()