tAllow relative URIs in article linkes. - zs - Zeitungsschau rss to email converter
 (HTM) git clone git://r-36.net/zs
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 86b129e4386789f5331765d7b96098e6c2c7bde7
 (DIR) parent 4010b280ba3871965b852aad19c26f9331e861bd
 (HTM) Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sun, 15 Apr 2018 11:35:39 +0200
       
       Allow relative URIs in article linkes.
       
       + Add feeduri for better filtering handling.
       
       Diffstat:
         zeitungsschau/feed.py               |      11 ++++++++---
         zeitungsschau/feeddb.py             |       4 ++--
         zeitungsschau/feedemail.py          |      21 ++++++++++++++++++++-
       
       3 files changed, 30 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/zeitungsschau/feed.py b/zeitungsschau/feed.py
       t@@ -414,9 +414,14 @@ def fetch(uri):
                                        ftype = "twtxt"
        
                if ftype == "xml":
       -                return (rcode, parseatomfeed(fval))
       +                rval = (rcode, parseatomfeed(fval))
                elif ftype == "twtxt":
       -                return (rcode, parsetwtxtfeed(fval.decode("utf-8"), uri))
       +                rval = (rcode, parsetwtxtfeed(fval.decode("utf-8"), uri))
                else:
       -                return (rcode, parsejsonfeed(fval.decode("utf-8")))
       +                rval = (rcode, parsejsonfeed(fval.decode("utf-8")))
       +        
       +        if rval[1] != None:
       +                rval[1]["feeduri"] = uri
       +        
       +        return rval
        
 (DIR) diff --git a/zeitungsschau/feeddb.py b/zeitungsschau/feeddb.py
       t@@ -215,7 +215,7 @@ class feeddb(object):
                        feed["articles"] = history[-2048:]
        
                        for metakey in ("link", "title", "updated", "author", \
       -                                "email"):
       +                                "email", "feeduri"):
                                if metakey in curfeed:
                                        feed[metakey] = curfeed[metakey]
        
       t@@ -232,7 +232,7 @@ class feeddb(object):
                                return rfeed
        
                        for metakey in ("link", "title", "updated", "author", \
       -                                "email", "toemail"):
       +                                "email", "toemail", "feeduri"):
                                if metakey in feed:
                                        rfeed[metakey] = feed[metakey]
        
 (DIR) diff --git a/zeitungsschau/feedemail.py b/zeitungsschau/feedemail.py
       t@@ -13,6 +13,7 @@ from email.header import Header
        import time
        import subprocess
        import lxml.html
       +import urllib.parse
        
        import html2text
        
       t@@ -96,9 +97,27 @@ def send(feed, to, smtphost="localhost", smtpport=None, ssl="False",\
                        msg["Subject"] = subject
        
                        if "link" in article:
       -                        msg["X-RSS-URL"] = article["link"]
       +                        if "://" not in article["link"]:
       +                                aurl = urllib.parse.urljoin(feed["feeduri"],\
       +                                        article["link"])
       +                                if "gopher://" in aurl:
       +                                        urls = urllib.parse.urlparse(aurl, \
       +                                                        allow_fragments=False)
       +                                        if urls.path.startswith("/0"):
       +                                                aurl = "%s://%s%s" % \
       +                                                (urls.scheme, urls.netloc, \
       +                                                        urls.path.replace(\
       +                                                        "/0", "/1", 1))
       +                                                if len(urls.query) > 0:
       +                                                        aurl = "%s?%s" % \
       +                                                        (aurl, urls.query)
       +                        else:
       +                                aurl = article["link"]
       +                        msg["X-RSS-URL"] = aurl
                        if "link" in feed:
                                msg["X-RSS-Feed"] = feed["link"]
       +                else:
       +                        msg["X-RSS-Feed"] = feed["feeduri"]
                        if "id" in article:
                                msg["X-RSS-ID"] = article["id"]
                        if "uuid" in article: