remove unnecessary imports
[mygpo.git] / mygpo / data / management / commands / update-related-podcasts.py
blob062b81645deea4f37dc91e416ebfe91dc763f70d
1 from django.core.management.base import BaseCommand
2 from optparse import make_option
3 from mygpo.api.models import Podcast
4 from mygpo.data.models import RelatedPodcast
5 from mygpo.data.podcast import calc_similar_podcasts
7 class Command(BaseCommand):
9 option_list = BaseCommand.option_list + (
10 make_option('--max', action='store', type='int', dest='max', default=15, help="Maximum number of similar podcasts to calculate for each podcast."),
14 def handle(self, *args, **options):
16 max_related = options.get('max')
18 podcasts = Podcast.objects.all().order_by('id').only('id')
20 for podcast in podcasts.iterator():
21 print podcast.id, podcast.title
23 l = calc_similar_podcasts(podcast)
25 RelatedPodcast.objects.filter(ref_podcast=podcast).delete()
26 for (p, count) in l[:max_related]:
27 RelatedPodcast.objects.create(ref_podcast=podcast, rel_podcast=p, priority=count)