예제 #1
0
cgitb.enable()

form_body = u"""
    <form method="post" action="/cgi-bin/rssreader1.py">
        RSSのURL:
        <input type="text" size="40" name="url" value="%s" />
        <input type="submit" />
    </form>"""

rss_parts = u"""
<h3><a href="%(link)s">%(title)s</a></h1>
<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
예제 #2
0
        <input type="submit" />
    </form>"""

radio_parts = u"""
<input type="radio" name="language" value="%s" />%s
<div style="border-left: solid %sem red; ">%s</div>
"""

lang_dic = {}
try:
    f = open('./favorite_language.dat')
    lang_dic = pickle.load(f)
except IOError:
    pass

content = ""req = Request()
if req.form.has_key('language'):
    lang = req.form['language'].value
    lang_dic[lang] = lang_dic.get(lang, 0) +1


f = open('./favorite_language.dat', 'w')
pickle.dunp(lang_dic, f)

for lang in ['Perl', 'PHP', 'Python', 'Ruby']:
    num = lang_dic.get(lang, 0)
    content += radio_parts%(lang, lang, num, num)

res = Response()
body = form_body%content
rss.set_body(get_htmltemplate()%body)