Skip to content
Permalink
Browse files

Now improves comments on user pages.

  • Loading branch information...
wiseman committed Jun 14, 2012
1 parent 0a188b0 commit 8f4f2f49d1348356139578fdf4ce16a3702f7baa
Showing with 46 additions and 0 deletions.
  1. +46 −0 activity_feed.py
@@ -107,6 +107,52 @@ def improve(self, item):
return self.improver(self, item)


# --------------------
# User page comments
# --------------------

def improve_user_page_comment(item_type, item):
needed_url = item['link']

def callback(url, html):
logging.info('%s callback for %s', item_type.name, url)
comment_body = extract_user_page_comment(url, html)
if not comment_body:
logging.error('Skipping improvement of item, could not find comment.')
else:
logging.info('Adding comment body to item')
summary = item['summary']
summary += '\n'
summary += comment_body
item['summary'] = summary

return Request(url=needed_url, callback=callback)


def extract_user_page_comment(url, soup):
idstr = user_page_comment_id_from_url(url)
logging.info('Looking for comment %s from url %s', idstr, url)
tag = soup.find(id=idstr)
if tag:
logging.info('Found comment: %s', tag_summary(tag))
return unicode(tag)
else:
logging.error('Could not find comment %s at url %s', idstr, url)
return None


def user_page_comment_id_from_url(url):
blog_id, comment_id = parse_comment_link(url)
return 'chatter-%s:Comment:%s' % (blog_id, comment_id)


ItemType.def_item_type(
name='USER PAGE COMMENT',
title_re=r'left a comment for',
link_re=r'http://diydrones.com/xn/detail/([0-9]+):Comment:([0-9]+)',
improver=improve_user_page_comment)


# --------------------
# Blog comments
# --------------------

0 comments on commit 8f4f2f4

Please sign in to comment.
You can’t perform that action at this time.