Skip to content

Commit

Permalink
Using the correct story permalink (if it is not correctly in the link…
Browse files Browse the repository at this point in the history
… key of the feed).
  • Loading branch information
samuelclay committed Dec 8, 2011
1 parent 369ad66 commit 04cb330
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions apps/rss_feeds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ def add_update_stories(self, stories, existing_stories, verbose=False):
if story.get('title'):
story_content = story.get('story_content')
story_tags = self.get_tags(story)
story_link = self.get_permalink(story)

existing_story, story_has_changed = self._exists_story(story, story_content, existing_stories)
if existing_story is None:
Expand All @@ -633,14 +634,13 @@ def add_update_stories(self, stories, existing_stories, verbose=False):
story_title = story.get('title'),
story_content = story_content,
story_author_name = story.get('author'),
story_permalink = story.get('link'),
story_permalink = story_link,
story_guid = story.get('guid'),
story_tags = story_tags
)
try:
s.save()
ret_values[ENTRY_NEW] += 1
cache.set('updated_feed:%s' % self.id, 1)
except (IntegrityError, OperationError), e:
ret_values[ENTRY_ERR] += 1
if verbose:
Expand Down Expand Up @@ -678,20 +678,19 @@ def add_update_stories(self, stories, existing_stories, verbose=False):
# logging.debug('\tExisting title / New: : \n\t\t- %s\n\t\t- %s' % (existing_story.story_title, story.get('title')))
if existing_story.story_guid != story.get('guid'):
self.update_read_stories_with_new_guid(existing_story.story_guid, story.get('guid'))

existing_story.story_feed = self.pk
existing_story.story_date = story.get('published')
existing_story.story_title = story.get('title')
existing_story.story_content = story_content_diff
existing_story.story_original_content = original_content
existing_story.story_author_name = story.get('author')
existing_story.story_permalink = story.get('link')
existing_story.story_permalink = story_link
existing_story.story_guid = story.get('guid')
existing_story.story_tags = story_tags
try:
existing_story.save()
ret_values[ENTRY_UPDATED] += 1
cache.set('updated_feed:%s' % self.id, 1)
except (IntegrityError, OperationError):
ret_values[ENTRY_ERR] += 1
if verbose:
Expand Down Expand Up @@ -784,20 +783,16 @@ def trim_feed(self, verbose=False):
userstories.delete()

def get_stories(self, offset=0, limit=25, force=False, slave=False):
stories = cache.get('feed_stories:%s-%s-%s' % (self.id, offset, limit), [])

if not stories or force:
if slave:
import pymongo
db = pymongo.Connection(['db01'], slave_okay=True, replicaset='nbset').newsblur
stories_db_orig = db.stories.find({"story_feed_id": self.pk})[offset:offset+limit]
stories_db = []
for story in stories_db_orig:
stories_db.append(bunch(story))
else:
stories_db = MStory.objects(story_feed_id=self.pk)[offset:offset+limit]
stories = Feed.format_stories(stories_db, self.pk)
cache.set('feed_stories:%s-%s-%s' % (self.id, offset, limit), stories)
if slave:
import pymongo
db = pymongo.Connection(['db01'], slave_okay=True, replicaset='nbset').newsblur
stories_db_orig = db.stories.find({"story_feed_id": self.pk})[offset:offset+limit]
stories_db = []
for story in stories_db_orig:
stories_db.append(bunch(story))
else:
stories_db = MStory.objects(story_feed_id=self.pk)[offset:offset+limit]
stories = Feed.format_stories(stories_db, self.pk)

return stories

Expand Down Expand Up @@ -859,7 +854,15 @@ def get_tags(self, entry):
fcat.append(tagname)
fcat = [t[:250] for t in fcat]
return fcat[:12]


def get_permalink(self, entry):
link = entry.get('link')
if not link:
links = entry.get('links')
if links:
link = links[0]['href']
return link

def _exists_story(self, story=None, story_content=None, existing_stories=None):
story_in_system = None
story_has_changed = False
Expand All @@ -874,11 +877,12 @@ def _exists_story(self, story=None, story_content=None, existing_stories=None):
# print 'Story pub date: %s %s' % (story_published_now, story_pub_date)
if (story_published_now or
(existing_story_pub_date > start_date and existing_story_pub_date < end_date)):
story_link = self.get_permalink(story)
if isinstance(existing_story.id, unicode):
existing_story.story_guid = existing_story.id
if story.get('guid') and story.get('guid') == existing_story.story_guid:
story_in_system = existing_story
elif story.get('link') and story.get('link') == existing_story.story_permalink:
elif story_link == existing_story.story_permalink:
story_in_system = existing_story

# Title distance + content distance, checking if story changed
Expand Down Expand Up @@ -917,7 +921,10 @@ def _exists_story(self, story=None, story_content=None, existing_stories=None):
if story_in_system:
if story_content != existing_story_content:
story_has_changed = True
if story_link != existing_story.story_permalink:
story_has_changed = True
break


# if story_has_changed or not story_in_system:
# print 'New/updated story: %s' % (story),
Expand Down

0 comments on commit 04cb330

Please sign in to comment.