Skip to content

Commit

Permalink
Add RSS Feed example
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpoletaev committed Mar 10, 2016
1 parent aba3560 commit 00c3f22
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/rss_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from tag import XMLDocument
from datetime import datetime
from collections import namedtuple


def get_posts():
Post = namedtuple('Post', ['title', 'description'])

return [
Post('Post1', 'Description1'),
Post('Post2', 'Description2'),
]


doc = XMLDocument('rss', attrs={
'xmlns:atom': 'http://www.w3.org/2005/Atom',
'version': '2.0',
})

with doc.channel():
doc.title('Hacker News')
doc.link('https://news.ycombinator.com/')
doc.description('Links for the intellectually curious, ranked by readers.')
now = datetime.now().isoformat()
doc.pubDate(now)

for post in get_posts():
with doc.item():
doc.title(post.title)
doc.description(post.description)
doc.pubDate(now)

print(doc.render())

0 comments on commit 00c3f22

Please sign in to comment.