Merge pull request #793 from gpodder/remove-advertise
[mygpo.git] / mygpo / data / management / commands / tag-downloader.py
blobc08e5862321b5b6de75d5e756852df23d7e1404c
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"
12 class Command(PodcastCommand):
13 """
14 Adds tags from the webservice delicious.com to podcasts
16 Podcasts are specified either by URL or the --toplist and --random
17 parameter. The delicious webservice is queried for the podcasts' websites.
18 The returned tags are added to the podcasts for the 'delicious' source.
19 """
21 def handle(self, *args, **options):
23 fetch_queue = self.get_podcasts()
25 for p in fetch_queue:
26 if not p or not p.link:
27 continue
29 # we don't want to spam delicious
30 time.sleep(1)
32 try:
33 f = urllib.request.urlopen(p.link)
34 except urllib.error.HTTPError:
35 continue
37 tags = delicious.get_tags(f.url)
39 self.update(podcast=p, tags=tags)
41 def update(self, podcast, tags):
42 podcast.tags[SOURCE] = tags
43 podcast.save()