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()
13 podcasts
= Podcast
.objects
.filter(url__in
=args
)
16 podcasts
= Podcast
.objects
.filter(group
=None).order_by('id').only('id')
18 for podcast
in podcasts
.iterator():
21 DirectoryEntry
.objects
.filter(podcast
=podcast
).delete()
23 for tag
, weight
in get_weighted_tags(podcast
, source_weights
).iteritems():
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():
33 DirectoryEntry
.objects
.filter(podcast_group
=group
).delete()
35 for tag
, weight
in get_weighted_group_tags(group
, source_weights
).iteritems():
39 DirectoryEntry
.objects
.create(podcast_group
=group
, tag
=tag
, ranking
=weight
)