From: Mart Lubbers Date: Mon, 5 May 2014 13:45:22 +0000 (+0200) Subject: working thing X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8feadf5087ddf14fcca4232f85c246044caa8c89;p=bsc-thesis1415.git working thing --- diff --git a/program/hypfront/hyper.py b/program/hypfront/hyper.py index 4405580..e773f86 100644 --- a/program/hypfront/hyper.py +++ b/program/hypfront/hyper.py @@ -2,8 +2,9 @@ # -*- coding: utf-8 -*- import feedparser -import HTMLParser -import feed2html +import urllib +import pprint +import re from mod_python import apache @@ -11,7 +12,8 @@ def req_pre(req): req.log_error('handler') req.content_type = 'text/html' req.send_http_header() - req.write(""" + req.write("""\ + HyperFrontend RSS feed input @@ -20,12 +22,27 @@ def req_pre(req): def req_post(req): - req.write(""" + req.write("""\ """) +def feed2html(req, url, name): + url = urllib.unquote(url) + url = url if re.match('https?://', url) else 'http://{}'.format(url) + req.write('\tLoading "{}" as "{}"
\n'.format(url, name)) + feed = feedparser.parse(url) + channel = feed.feed + req.write('\t\n') + req.write('\t\t\n') + for i in feed.entries: + req.write('\t\t\n'. + format(i['title'].encode('ascii', 'xmlcharrefreplace'))) + + req.write('\t
Title...
{}...
\n') + + def handler(req): req_pre(req) args = dict(filter(lambda x: x[1], @@ -35,6 +52,6 @@ def handler(req): req.write('Something went wrong, empty fields?
') req.write('back') else: - req.write(str(args)) + feed2html(req, args['url'], args['name']) req_post(req) return apache.OK