From 4767b78927e677118e2d768ba5f7e8f326471c9d Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 5 May 2014 13:44:11 +0200 Subject: [PATCH] started with frontend --- program/hypfront/feed2html.py | 278 +++++++++++++++++++++++++++++++++ program/hypfront/feed2html.pyc | Bin 0 -> 10184 bytes program/hypfront/hyper.py | 40 +++++ program/hypfront/index.html | 11 ++ program/hypfront/install.sh | 3 + program/hypfront/test.html | 136 ++++++++++++++++ 6 files changed, 468 insertions(+) create mode 100644 program/hypfront/feed2html.py create mode 100644 program/hypfront/feed2html.pyc create mode 100644 program/hypfront/hyper.py create mode 100644 program/hypfront/index.html create mode 100644 program/hypfront/install.sh create mode 100644 program/hypfront/test.html diff --git a/program/hypfront/feed2html.py b/program/hypfront/feed2html.py new file mode 100644 index 0000000..436bdc1 --- /dev/null +++ b/program/hypfront/feed2html.py @@ -0,0 +1,278 @@ +#!/usr/bin/env python +import sys +import feedparser + +import getopt +import os +import re +import time + +DEFAULT_TEMPLATE = """\ + + + + " /> + <tpl:feed value="title" filter="xml" /> + + +
+

">

+
+ +
+

">

+
+

Posted by on

+
+
+
+
+ + +""" + +class Template: + """Generic template library. Initially implemented in bloglines2html.py""" + + re_parse = re.compile(r'|>(.*?))', + re.U | re.S) + re_parse_attr = re.compile(r'([a-z]+)\s*=\s*"([^"]*)"', re.U|re.I) + + # Default Date/Time format + datetime_format = '%Y-%m-%d %H:%M:%S' + + def __init__(self): + self.var = {} + + def format_datetime(self, data, format): + return time.strftime(format, data) + + def get_charset(self): + return 'utf-8' + + def parse(self, text): + return self.re_parse.sub(self.process_tag, text) + + def parse_attr(self, text): + return dict(self.re_parse_attr.findall(text.strip())) + + def process_tag(self, match): + tag = match.group(1) + attr = self.parse_attr(match.group(2)) + data = match.group(3) or u'' + + try: + handler = getattr(self, 'tag_%s' % tag) + except AttributeError: + return '' + else: + result = handler(attr, data) + if result is None: + result = '' + elif (isinstance(result, tuple) or + isinstance(result, time.struct_time)) and len(result) == 9: + result = self.format_datetime(result, + attr.get('format', self.datetime_format)) + + if 'filter' in attr: + result = do_filters(result, attr['filter']) + + if isinstance(result, unicode): + result = result.encode(self.get_charset()) + else: + result = str(result) + + return result + + def tag_charset(self, attr, data): + return self.get_charset() + + def tag_var(self, attr, data): + # Handle + val = self.var.get(attr.get('name'), attr.get('default', '')) + if isinstance(val, unicode): + val = val.encode(self.get_charset()) + return val + + +class RSSTemplate(Template): + """Template with tag handlers for feed data.""" + + re_range = re.compile(r'([\-\d]+)?(:([\-\d]+)?(:([\-\d]+)?)?)?') + + def __init__(self, feed): + Template.__init__(self) + self.feed = feed + self.content = None + self.contributors = None + self.enclosures = None + self.entries = None + + def get_charset(self): + return self.feed.encoding + + def get_loop(self, obj, objattr, attr, data): + def range_value(val): + if val is None: + return val + else: + return int(val) + + if obj: + items = obj.get(objattr) + if items: + result = [] + if 'select' in attr: + match = self.re_range.match(attr['select']) + if match: + # Only a single item is selected. + match = [range_value(x) + for x in list(match.group(1, 3, 5))] + items = items[slice(*match)] + + for item in items: + setattr(self, objattr, item) + result.append(self.parse(data)) + + setattr(self, objattr, None) + return ''.join(result) + + return '' + + def get_value(self, obj, attr, data): + if (obj is not None) and ('value' in attr): + key = attr['value'] + detail = attr.get('detail') + value = None + + # Check whether it is requesting a datetime field. + if (key+'_parsed') in obj: + return obj.get(key+'_parsed') + + # Check whether it is trying to get details. + if detail: + obj2 = attr.get('%s_detail' % key) + if obj2: + value = obj2.get(detail) + else: + value = obj.get(key) + + if isinstance(value, basestring): + return value + + return '' + + def tag_content(self, attr, data): + return self.get_value(self.content, attr, data) + + def tag_contents(self, attr, data): + return self.get_loop(self.entries, 'content', attr, data) + + def tag_contributor(self, attr, data): + return self.get_value(self.contributors, attr, data) + + def tag_contributors(self, attr, data): + return self.get_loop(self.entries, 'contributors', attr, data) + + def tag_enclosure(self, attr, data): + return self.get_value(self.enclosures, attr, data) + + def tag_enclosures(self, attr, data): + return self.get_loop(self.entries, 'enclosures', attr, data) + + def tag_entries(self, attr, data): + return self.get_loop(self.feed, 'entries', attr, data) + + def tag_entry(self, attr, data): + return self.get_value(self.entries, attr, data) + + def tag_feed(self, attr, data): + return self.get_value(self.feed.feed, attr, data) + + def tag_if_not(self, attr, data): + # Handle ... + try: + handler = getattr(self, 'tag_%s' % attr['tag']) + except (AttributeError, KeyError): + pass + else: + val = handler(attr, data) + match = attr.get('match') + + if ((not match) and (not val)) or (match and (val != match)): + return self.parse(data) + + return self.parse(data) + + def tag_if(self, attr, data): + # Handle ... + try: + handler = getattr(self, 'tag_%s' % attr['tag']) + except (AttributeError, KeyError): + pass + else: + val = handler(attr, data) + match = attr.get('match') + + if ((not match) and val) or (match and (val == match)): + return self.parse(data) + + return '' + + def tag_now(self, attr, data): + # Handle + return time.localtime() + + +def do_filters(data, filters): + for f in filters.split(','): + f = f.strip() + + # Try to find the filter using the global name space. + try: + f = globals()['filter_%s' % f] + except KeyError: + pass + else: + data = f(data) + + return data + + +def filter_basename(data): + """Return the basename of the filename.""" + idx = data.rfind('/') + if idx < 0: + idx = data.rfind('\\') + if idx < 0: + return data + + return data[idx+1:] + + +def filter_reducespace(data): + return re.sub(r'[\t\r\n\s]+', ' ', data).strip() + + +def filter_xml(data): + """Escape the XML entities.""" + data = data.replace('&', '&') + data = data.replace('<', '<') + data = data.replace('>', '>') + return data + + +def filter_xmlq(data): + """Escape the XML entities + quote, useful for XML attributes.""" + data = filter_xml(data) + data = data.replace('"', '"') + return data + + +def rss2html(inp): + # Parse the feed data and supply that to RSSTemplate object + template = RSSTemplate(inp) + + result = template.parse(DEFAULT_TEMPLATE) + + return result diff --git a/program/hypfront/feed2html.pyc b/program/hypfront/feed2html.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7c1e6ba31da6b0a2279ef8c7e3b9427c73105aca GIT binary patch literal 10184 zcmb_iU2hymcCDTneu@$)*^;caHtwC6@<-ka zM0N3Yb#>LLdvBe4tD5ECA0Pe7tTvh||5wKETe$Rpp$PHcQEjD`da|RIoT9#@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gs<=<29yA@dRolg$5k2?{BnmypokLfC#Y zKRaaDk^ps1j?>CGPCJX^G=~ACg?NTTwGVixmfTYhk%Z-Jg)=pTB}5!#S(0BdjT=y7 zS-@a5rZw-fzvK;sjk3t#Jqd^s;dbBHo#U?aEAIjzN@TCm+LtOz2&3lWmY<~NKhaQg)1iK6~~8ZGidMq#?a3w4qKPZV+aY~*!~-$ zjeVsWGXd`hEIwp$jRijecsE#l!h+0U_wf>aB`a8F-D4JCu;AgF_fr-Dixn1479ook zi&Yjeiatn@_W7Q76OEqW(r=^S27kOXGK>xV`H{2zZGBG~9~qY&D-}t#iz12Vnav_) zSB3R8|M+7$U6cvU>_GvC@$lOig@cbO=9waAwN9TXaRlYR=&%|@tbnGaF`v}EbZz(ZauChKXe7KGj~886^dL+LJxG2@bIWcNpRZo@OsN?} zA1#~ZY&luhkKYyiuC^54ywcgdupc9EX9^!9YkQLywZltYAE@+a;g` zNw9gd^DXSuo3CAOnymCSvvc2dx4QVtg3E4KN3AaYP5>uhoIZEV^6e&9Kvjam1vb86 z{cjt+de2b2+6?I^{TXh3ms2G5D180MCrFdh%3{{HAoM3F%M6Z4>cM=4dJ3-RYr=nW zBw)D4=kNaTqtEUw`iplzy?^hc#k=B=vUQA;js$;f@8!=GWb=QRN74+Lwx96d-US*2 zYhOD}pv0iJ?U5T3C;5_TzZ7BHnRX0-E0t;+CM1f!iwbXwFLMZAK3(JFn0oSk9(*Jk zr^? + + HyperFrontend RSS feed input + + +""") + + +def req_post(req): + req.write(""" + + +""") + + +def handler(req): + req_pre(req) + args = dict(filter(lambda x: x[1], + map(lambda x: x.split('='), + req.__getattribute__('args').split('&')))) + if 'url' not in args and 'name' not in args: + req.write('Something went wrong, empty fields?
') + req.write('back') + else: + req.write(str(args)) + req_post(req) + return apache.OK diff --git a/program/hypfront/index.html b/program/hypfront/index.html new file mode 100644 index 0000000..db11dec --- /dev/null +++ b/program/hypfront/index.html @@ -0,0 +1,11 @@ + + +
+ + + +

RSS URL:

RSS Name:

+
+
+ + diff --git a/program/hypfront/install.sh b/program/hypfront/install.sh new file mode 100644 index 0000000..1cb3451 --- /dev/null +++ b/program/hypfront/install.sh @@ -0,0 +1,3 @@ +sudo rm -v /var/www/py/* +sudo cp -v ./*.py ./*.html /var/www/py/ +sudo chown -vR www-data:www-data /var/www/py diff --git a/program/hypfront/test.html b/program/hypfront/test.html new file mode 100644 index 0000000..4cdf35b --- /dev/null +++ b/program/hypfront/test.html @@ -0,0 +1,136 @@ + + + + + Nieuw in de voorverkoop Paradiso + + +
+

Nieuw in de voorverkoop Paradiso

+
+ +
+

donderdag 26 juni 2014 23:30 - Dondergrondse: Fuck Forever band night

+
+

Posted by on

+
+ +
+

donderdag 19 juni 2014 23:30 - Dondergrondse

+
+

Posted by on

+
+ +
+

zaterdag 7 juni 2014 20:00 - Kina Grannis - Locatie: Bitterzoet

+
+

Posted by on

+
+ +
+

vrijdag 3 oktober 2014 19:30 - Jay Brannan

+
+

Posted by on

+
+ +
+

donderdag 12 juni 2014 23:30 - Dondergrondse: hosted by The Daily Indie – Live: The Future’s Dust

+
+

Posted by on

+
+ +
+

woensdag 23 juli 2014 20:00 - Blitz Kids

+
+

Posted by on

+
+ +
+

donderdag 26 juni 2014 23:30 - Noodlanding!

+
Dansnacht, alternatieve hits
+

Posted by on

+
+ +
+

donderdag 19 juni 2014 23:30 - Noodlanding!

+
Dansnacht, alternatieve hits
+

Posted by on

+
+ +
+

maandag 15 september 2014 19:30 - Natural Child – 3VOOR12 presents - Locatie: Tolhuistuin (zaal)

+
aftrap officiële openingsweek van nieuwe zaal Tolhuistuin
+

Posted by on

+
+ +
+

zaterdag 5 juli 2014 22:00 - Ben Miller Band

+
+

Posted by on

+
+ +
+

donderdag 16 oktober 2014 20:30 - Zoot Woman – ADE - Locatie: Tolhuistuin (zaal)

+
+

Posted by on

+
+ +
+

woensdag 25 juni 2014 21:00 - Little Barrie - Locatie: Bitterzoet

+
+

Posted by on

+
+ +
+

woensdag 3 september 2014 19:30 - Earth Wind & Fire Experience feat. Al McKay

+
+

Posted by on

+
+ +
+

zondag 19 oktober 2014 19:00 - Di-rect

+
+

Posted by on

+
+ +
+

vrijdag 10 oktober 2014 19:30 - Royal Wood

+
+

Posted by on

+
+ +
+

zondag 1 juni 2014 20:00 - Dark Alley Cabaret

+
Amsterdam Burlesque Weekend
+

Posted by on

+
+ +
+

maandag 2 juni 2014 20:30 - The News – Reality Opera van Jacob TV door de Nederlandse Reisopera

+
+

Posted by on

+
+ +
+

zaterdag 24 mei 2014 21:00 - ‘Wij zijn 18’: filmpremiere, Palio Superspeed Donkey & afterparty

+
+

Posted by on

+
+ +
+

maandag 30 juni 2014 20:30 - Wiz Khalifa

+
+

Posted by on

+
+ +
+

woensdag 20 augustus 2014 21:00 - Dave Hause - Locatie: Bitterzoet

+
+

Posted by on

+
+ +
+ +
+ + -- 2.20.1