From d242930a6f33717c89a4559ebbdfd83264495ebe Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 8 May 2014 09:42:33 +0200 Subject: [PATCH] things --- program/hypfront/.gitignore | 1 - program/hypfront/feed2html.py | 278 ---------------------------------- program/hypfront/install.sh | 3 + program/hypfront/test.html | 136 ----------------- 4 files changed, 3 insertions(+), 415 deletions(-) delete mode 100644 program/hypfront/feed2html.py create mode 100644 program/hypfront/install.sh delete mode 100644 program/hypfront/test.html diff --git a/program/hypfront/.gitignore b/program/hypfront/.gitignore index f1391d9..0d20b64 100644 --- a/program/hypfront/.gitignore +++ b/program/hypfront/.gitignore @@ -1,2 +1 @@ *.pyc -install.sh diff --git a/program/hypfront/feed2html.py b/program/hypfront/feed2html.py deleted file mode 100644 index 436bdc1..0000000 --- a/program/hypfront/feed2html.py +++ /dev/null @@ -1,278 +0,0 @@ -#!/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/install.sh b/program/hypfront/install.sh new file mode 100644 index 0000000..474783d --- /dev/null +++ b/program/hypfront/install.sh @@ -0,0 +1,3 @@ +sudo rm -v /var/www/py/* +sudo cp -v --preserve ./*.{py,html,js} /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 deleted file mode 100644 index 4cdf35b..0000000 --- a/program/hypfront/test.html +++ /dev/null @@ -1,136 +0,0 @@ - - - - - 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