remove unnecessary imports
[mygpo.git] / mygpo / data / management / commands / update-directory.py
blob7935daf5df8b832edbfe5841a7ef6e4fc8cb003d
1 from django.core.management.base import BaseCommand
2 from mygpo.api.models import Podcast, PodcastGroup
3 from mygpo.data.models import DirectoryEntry
4 from mygpo.data.directory import get_source_weights, get_weighted_tags, get_weighted_group_tags
6 class Command(BaseCommand):
8 def handle(self, *args, **options):
10 source_weights = get_source_weights()
12 if len(args) > 0:
13 podcasts = Podcast.objects.filter(url__in=args)
15 else:
16 podcasts = Podcast.objects.filter(group=None).order_by('id').only('id')
18 for podcast in podcasts.iterator():
20 print podcast.id
21 DirectoryEntry.objects.filter(podcast=podcast).delete()
23 for tag, weight in get_weighted_tags(podcast, source_weights).iteritems():
24 if weight == 0:
25 continue
27 DirectoryEntry.objects.create(podcast=podcast, tag=tag, ranking=weight)
29 groups = PodcastGroup.objects.all().order_by('id').only('id')
30 for group in groups.iterator():
32 print group.id
33 DirectoryEntry.objects.filter(podcast_group=group).delete()
35 for tag, weight in get_weighted_group_tags(group, source_weights).iteritems():
36 if weight == 0:
37 continue
39 DirectoryEntry.objects.create(podcast_group=group, tag=tag, ranking=weight)