zs

Zeitungsschau rss to email converter
git clone git://r-36.net/zs
Log | Files | Refs | LICENSE

commit 6931d72c70b47e9feb2be879260718592d0148e0
parent 323c0f1b002f9614c76c14c47a2af4b39b4c5163
Author: Christoph Lohmann <20h@r-36.net>
Date:   Tue, 21 Mar 2017 19:42:37 +0100

First gopher support.

Diffstat:
zeitungsschau/feed.py | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/zeitungsschau/feed.py b/zeitungsschau/feed.py @@ -14,6 +14,8 @@ import hashlib import pytz import codecs import html +import urllib.parse +import socket def parseiso(dstr, now): try: @@ -242,6 +244,29 @@ def fetch(uri): fval = fd.read().encode("utf-8") fd.close() rcode = 200 + elif "gopher://" in uri: + urls = urllib.parse.urlparse(uri, allow_fragments=False) + if ":" in urls.netloc: + (host, port) = urls.netloc.split(":") + else: + host = urls.netloc + port = 70 + if len(path) > 2: + if len(urls.query) > 0: + selector = "%s?%s" % (urls.path[2:], urls.query) + else: + selector = urls.path[2:] + else: + selector = "" + + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((host, port)) + s.send("%s\r\n" % (selector)) + s.shutdown(1) + fd = s.makefile("r") + fval = fd.read().encode("utf-8") + fd.close() + rcode = 200 else: fd = requests.get(uri, timeout=20,\ headers={"User-Agent": "Zeitungsschau/1.0"})