73694880348622e035a03a7002cfa7711595531a
1 from django
.core
.management
.base
import BaseCommand
2 from mygpo
.api
.models
import Podcast
, Episode
3 from mygpo
.api
.sanitizing
import rewrite_podcasts
, rewrite_episodes
4 from mygpo
.data
import feeddownloader
5 from optparse
import make_option
8 class Command(BaseCommand
):
10 def handle(self
, *args
, **options
):
14 for p
in Podcast
.objects
.only('id', 'url'):
15 if Podcast
.objects
.filter(url__exact
=p
.url
).exclude(id=p
.id).exists():
16 print 'found podcast url %s' % p
.url
17 podcast_urls
.append(p
.url
)
20 for e
in Episode
.objects
.only('id', 'url'):
21 if Episode
.objects
.filter(url__exact
=e
.url
, podcast
=e
.podcast
).exclude(id=e
.id).exists():
22 print 'found episode url %s' % e
.url
23 episode_ids
.append(e
.id)
28 for url
in podcast_urls
:
29 p
= Podcast
.objects
.filter(url
=url
).order_by('id')[0]
30 for p2
in Podcast
.objects
.filter(url
=url
).exclude(id=p
.id).order_by('id'):
31 print 'merging podcast %s with %s' % (p
.id, p2
.id)
32 rewrite_podcasts(p2
, p
)
35 for e_id
in episode_ids
:
36 e
= Episode
.objects
.get(id=e_id
)
37 for e2
in Episode
.objects
.filter(url
=e
.url
, podcast
=e
.podcast
).exlcude(id=e
.id).order_by('id'):
38 print 'merging episode %s with %s' % (e
.id, e2
.id)
39 rewrite_episodes(e2
, e
)