Commit 13a16677 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

improve feed parsing and display of microblogs

parent 411f1f56c998
......@@ -97,4 +97,8 @@ div.microblog span.msgtxt {
div.microblog span.meta {
color: #999;
display: block;
}
div.microblog span.meta a {
color: #999;
}
\ No newline at end of file
......@@ -89,7 +89,7 @@ class BlogEntryISiocItemAdapter(EntityAdapter):
return self.entity.content
def isioc_container(self):
return self.entity.parent()
return self.entity.entry_of
def isioc_type(self):
return 'BlogPost'
......
......@@ -126,15 +126,41 @@ def parse_microblogpost_rss(url):
for entry in feed.entries:
item = {}
item['uri'] = entry.id
item['content'] = entry.description.split(':',1)[1][:140]
# fix weird parsing
if hasattr(entry, 'content'):
content = entry.content[0].value
mimetype = entry.content[0].type
else:
content = entry.description
mimetype = u'text/plain'
if ': ' in content:
author, text = content.split(': ', 1)
if ' ' not in author:
content = text
item['content'] = content
item['content_format'] = format_map.get(mimetype, u'text/plain')
item['creation_date'] = datetime(*entry.date_parsed[:6])
item['modification_date'] = datetime(*entry.date_parsed[:6])
item['author'] = feed.channel.link # true for twitter
item['cwuri'] = feed.channel.link
screen_name = feed.channel.link.split('/')[-1]
item['avatar'] = get_twitter_avatar(screen_name)
for link in entry.links:
if link.type.startswith('image/') and link.rel == 'image':
item['avatar'] = link.href
break
else:
screen_name = feed.channel.link.split('/')[-1]
item['avatar'] = get_twitter_avatar(screen_name)
yield item
def search_twitter(word):
import urllib2
from simplejson import loads
data = urllib2.urlopen('http://search.twitter.com/search.json?q=%s&rpp=100' % word).read()
results = loads(data)
# process results
# print results
return []
AVATAR_CACHE = {}
def get_twitter_avatar(screen_name):
......
......@@ -121,19 +121,22 @@ def format_microblog(entity):
xml_escape(imgurl))
else:
ablock = entity.has_creator[0].view('outofcontext')
words = []
for word in entity.content.split():
if word.startswith('http://'):
word = u'<a href="%s">%s</a>' % (word, word)
else:
word = xml_escape(word)
words.append(word)
content = u' '.join(words)
if entity.content_format == 'text/html':
content = entity.content
else:
words = []
for word in entity.content.split():
if word.startswith('http://'):
word = u'<a href="%s">%s</a>' % (word, word)
else:
word = xml_escape(word)
words.append(word)
content = u' '.join(words)
return (u'<div class="microblog">'
u'<span class="author">%s</span>'
u'<span class="msgtxt">%s</span>'
u'<span class="meta">%s</span>'
u'</div>' % (ablock, content, entity.creation_date))
u'<span class="meta"><a href="%s">%s</a></span>'
u'</div>' % (ablock, content, entity.absolute_url(), entity.creation_date))
class MicroBlogEntryPrimaryView(primary.PrimaryView):
__select__ = primary.PrimaryView.__select__ & is_instance('MicroBlogEntry')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment