Feed date scraper for Gemini (protocol)
connection: timeout after 2 seconds
Zach DeCook 2021-02-07
parent 6ae0102 · commit 6da92c8
-rwxr-xr-xzachwalk.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/zachwalk.py b/zachwalk.py
index 2c2c3ea..a7d1a8d 100755
--- a/zachwalk.py
+++ b/zachwalk.py
@@ -12,13 +12,15 @@ def getnewestdate(url):
"""load the url, and find the newest date listed in a link"""
# TODO: outsource to pre-installed cli program?
hostname = url.split('/')[2]
- s = socket.create_connection((hostname, 1965))
+ try:
+ s = socket.create_connection((hostname, 1965),timeout=2)
+ except:
+ return DEFAULT
context = ssl.SSLContext()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
s = context.wrap_socket(s, server_hostname = hostname)
s.sendall((url + '\r\n').encode("UTF-8"))
- # Get header and check for redirects
fp = s.makefile("rb")
header = fp.readline()
header = header.decode("UTF-8").strip()