From fe82b19c9101c1d27fa5a90a83bd0e91cdbc1db4 Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 15 Apr 2020 22:30:45 +0200 Subject: [PATCH] Merge .xsl & html template Turns out they somehow serve a similar purpose --- morss/feedify.ini | 4 +- morss/feeds.py | 20 +++- morss/reader.html.template | 196 ------------------------------------- setup.py | 2 +- www/sheet.xsl | 124 ++++++++++------------- 5 files changed, 67 insertions(+), 279 deletions(-) delete mode 100644 morss/reader.html.template diff --git a/morss/feedify.ini b/morss/feedify.ini index 6059c7a..291f21e 100644 --- a/morss/feedify.ini +++ b/morss/feedify.ini @@ -94,7 +94,7 @@ path = http://localhost/ title = //div[@id='header']/h1 -desc = //div[@id='header']/h2 +desc = //div[@id='header']/p items = //div[@id='content']/div item_title = ./a @@ -102,7 +102,7 @@ item_link = ./a/@href item_desc = ./div[class=desc] item_content = ./div[class=content] -base = file:reader.html.template +base = file:www/sheet.xsl [twitter] mode = html diff --git a/morss/feeds.py b/morss/feeds.py index ef5348f..019f877 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -46,10 +46,23 @@ def parse_rules(filename=None): rules = dict([(x, dict(config.items(x))) for x in config.sections()]) for section in rules.keys(): + # for each ruleset + for arg in rules[section].keys(): + # for each rule + if rules[section][arg].startswith('file:'): - import_file = os.path.join(os.path.dirname(__file__), rules[section][arg][5:]) - rules[section][arg] = open(import_file).read() + paths = [os.path.join(sys.prefix, 'share/morss', rules[section][arg][5:]), + os.path.join(os.path.dirname(__file__), '..', rules[section][arg][5:])] + + for path in paths: + try: + file_raw = open(path).read() + file_clean = re.sub('<[/?]?(xsl|xml)[^>]+?>', '', file_raw) + rules[section][arg] = file_clean + + except IOError: + pass elif '\n' in rules[section][arg]: rules[section][arg] = rules[section][arg].split('\n')[1:] @@ -293,10 +306,7 @@ class ParserXML(ParserBase): NSMAP = {'atom': 'http://www.w3.org/2005/Atom', 'atom03': 'http://purl.org/atom/ns#', - 'media': 'http://search.yahoo.com/mrss/', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', - 'slash': 'http://purl.org/rss/1.0/modules/slash/', - 'dc': 'http://purl.org/dc/elements/1.1/', 'content': 'http://purl.org/rss/1.0/modules/content/', 'rssfake': 'http://purl.org/rss/1.0/'} diff --git a/morss/reader.html.template b/morss/reader.html.template deleted file mode 100644 index dfff1e4..0000000 --- a/morss/reader.html.template +++ /dev/null @@ -1,196 +0,0 @@ - - - - Feed reader by morss - - - - - - - - - -
-
- -
-
-
-
- - - - diff --git a/setup.py b/setup.py index 07ecbb1..2ed440f 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ setup( license = 'AGPL v3', packages = [package_name], install_requires = ['lxml', 'bs4', 'python-dateutil', 'chardet', 'pymysql'], - package_data = {package_name: ['feedify.ini', 'reader.html.template']}, + package_data = {package_name: ['feedify.ini']}, data_files = [ ('share/' + package_name, ['README.md', 'LICENSE']), ('share/' + package_name + '/www', glob('www/*.*')), diff --git a/www/sheet.xsl b/www/sheet.xsl index c885d5b..c6d263e 100644 --- a/www/sheet.xsl +++ b/www/sheet.xsl @@ -1,13 +1,22 @@ - + + RSS feed by morss + @@ -65,59 +54,44 @@
-
    - -
+
+ + + +
+ +
+ + + + +
+ +
+ +
+ +
+
+
+
- - -
  • - - < - - - - - = - "" - - > - - - -
      - -
    -
    - - - </ - - > - -
  • -
    - - -
  • -
    ]]>
    -
  • -
    - - -
  • -
    -				
    -			
    -
  • -
    - - -