2010-06-27 22:40:22 -04:00
|
|
|
from django.core.management.base import BaseCommand
|
2010-09-08 16:00:20 -07:00
|
|
|
from apps.rss_feeds.models import merge_feeds, MStory
|
2010-06-27 22:40:22 -04:00
|
|
|
from optparse import make_option
|
2010-07-20 22:57:18 -04:00
|
|
|
from django.db import connection
|
2010-06-27 22:40:22 -04:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option("-f", "--feed", dest="feed", default=None),
|
|
|
|
make_option("-V", "--verbose", dest="verbose", action="store_true"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2010-07-20 22:57:18 -04:00
|
|
|
cursor = connection.cursor()
|
|
|
|
cursor.execute("""SELECT DISTINCT f.id AS original_id, f2.id AS duplicate_id,
|
|
|
|
f.feed_address AS original_feed_address,
|
2010-09-08 16:00:20 -07:00
|
|
|
f2.feed_address AS duplicate_feed_address,
|
|
|
|
f.feed_title AS original_feed_title,
|
|
|
|
f2.feed_title AS duplicate_feed_title,
|
|
|
|
f.feed_link AS original_feed_link,
|
|
|
|
f2.feed_link AS duplicate_feed_link,
|
|
|
|
f2.feed_tagline AS original_feed_tagline,
|
|
|
|
f.feed_tagline AS duplicate_feed_tagline
|
|
|
|
FROM feeds f, feeds f2
|
|
|
|
WHERE f2.id > f.id
|
2010-07-20 22:57:18 -04:00
|
|
|
AND f.feed_tagline = f2.feed_tagline
|
|
|
|
AND f.feed_link = f2.feed_link
|
2010-07-20 23:40:09 -04:00
|
|
|
AND f.feed_title = f2.feed_title
|
2010-09-08 16:06:27 -07:00
|
|
|
ORDER BY original_id ASC;""")
|
2010-09-08 16:04:12 -07:00
|
|
|
|
2010-07-20 22:57:18 -04:00
|
|
|
feed_fields = ('original_id', 'duplicate_id', 'original_feed_address', 'duplicate_feed_address')
|
|
|
|
for feeds_values in cursor.fetchall():
|
|
|
|
feeds = dict(zip(feed_fields, feeds_values))
|
|
|
|
|
2010-09-08 16:06:27 -07:00
|
|
|
original_stories = MStory.objects(story_feed_id=int(feeds['original_id'])).only('story_guid')[10:13]
|
2010-09-08 16:08:01 -07:00
|
|
|
print original_stories
|
2010-09-08 16:00:20 -07:00
|
|
|
original_story_ids = [story.id for story in original_stories]
|
2010-09-08 16:08:01 -07:00
|
|
|
print original_story_ids
|
|
|
|
duplicate_stories = MStory.objects(story_feed_id=int(feeds['duplicate_id']), story_guid__in=original_story_ids)
|
|
|
|
print duplicate_stories
|
|
|
|
if duplicate_stories.count() != original_stories.count():
|
2010-09-08 16:00:20 -07:00
|
|
|
print "Skipping: %s" % (feeds)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
print "Merging: %s" % feeds
|
|
|
|
# merge_feeds(feeds['original_id'], feeds['duplicate_id'])
|