# -*- coding: utf-8 -*-
import feedparser
-import HTMLParser
-import feed2html
+import urllib
+import pprint
+import re
from mod_python import apache
req.log_error('handler')
req.content_type = 'text/html'
req.send_http_header()
- req.write("""<html>
+ req.write("""\
+<html>
<head>
<title>HyperFrontend RSS feed input</title>
</head>
def req_post(req):
- req.write("""
+ req.write("""\
</body>
</html>
""")
+def feed2html(req, url, name):
+ url = urllib.unquote(url)
+ url = url if re.match('https?://', url) else 'http://{}'.format(url)
+ req.write('\tLoading "{}" as "{}"<br />\n'.format(url, name))
+ feed = feedparser.parse(url)
+ channel = feed.feed
+ req.write('\t<table border="1">\n')
+ req.write('\t\t<tr><th>Title</th><th>...</th></tr>\n')
+ for i in feed.entries:
+ req.write('\t\t<tr><td>{}</td><td>...</td></tr>\n'.
+ format(i['title'].encode('ascii', 'xmlcharrefreplace')))
+
+ req.write('\t</table>\n')
+
+
def handler(req):
req_pre(req)
args = dict(filter(lambda x: x[1],
req.write('Something went wrong, empty fields?<br />')
req.write('<a href="index.html">back</a>')
else:
- req.write(str(args))
+ feed2html(req, args['url'], args['name'])
req_post(req)
return apache.OK