PageRenderTime 142ms CodeModel.GetById 80ms app.highlight 3ms RepoModel.GetById 57ms app.codeStats 0ms

/kai/lib/serialization.py

https://bitbucket.org/bbangert/kai/
Python | 26 lines | 24 code | 2 blank | 0 comment | 3 complexity | 3dc1ba83f84813d98875e2b415f0031c MD5 | raw file
 1import datetime
 2
 3from couchdb.schema import Document
 4from webhelpers.feedgenerator import Atom1Feed
 5
 6def render_feed(title, link, description, objects, pub_date=None):
 7    feed = Atom1Feed(title=title, link=link, description=description)
 8    for obj in objects:
 9        if isinstance(obj, dict):
10            title = obj.get('title', 'No title')
11            link = obj.get('link', '')
12            description = obj.get('description', '')
13            if pub_date:
14                date = obj.get(pub_date)
15            else:
16                date = obj.get('feed_pub_date', '')
17        else:
18            title = obj.feed_title
19            link = obj.feed_link
20            description = obj.feed_description
21            if pub_date:
22                date = getattr(obj, pub_date)
23            else:
24                date = obj.feed_pub_date
25        feed.add_item(title=title, link=link, pubdate=date, description=description)
26    return feed.writeString('utf-8')