Skip to content

Instantly share code, notes, and snippets.

@FiNGAHOLiC
Created January 23, 2012 06:49
Show Gist options
  • Select an option

  • Save FiNGAHOLiC/1661289 to your computer and use it in GitHub Desktop.

Select an option

Save FiNGAHOLiC/1661289 to your computer and use it in GitHub Desktop.
rssreader1.py
#! /usr/bin/env python
# coding: urf-8
from rssparser import parse_rss
from httphandler import Request, Response, get_htmltemplate
import cgitb; cgitb.enable()
form_body = u"""
<form method="POST" action="/cgi-bin/rssreader1.py">
<p>RSSのURL <input type="text" size="40" name="url" value="%s"></p>
<p><input type="submit"></p>
</form>"""
rss_parts = u"""
<h3><a href="%(link)s">%(title)s</a></h3>
<p>%(description)s</p>
"""
content = u"URLを入力してください"
req = Request()
if req.form.has_key('url'):
try:
rss_list = parse_rss(req.form['url'].value)
content = ""
for d in rss_list:
content += rss_parts % d
except:
pass
res = Response()
body = form_body % req.form.getvalue('url', '')
body += content
res.set_body(get_htmltemplate() % body)
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment