added a timeout

This commit is contained in:
Lynne 2018-10-27 22:07:38 +10:00
parent eeba1c9066
commit 0c97743ffd

View file

@ -147,17 +147,17 @@ for f in following:
# print("{} is on {}".format(f.acct, instance)) # print("{} is on {}".format(f.acct, instance))
try: try:
r = requests.get("https://{}/.well-known/host-meta".format(instance)) r = requests.get("https://{}/.well-known/host-meta".format(instance), timeout=10)
uri = re.search(r'template="([^"]+)"', r.text).group(1) uri = re.search(r'template="([^"]+)"', r.text).group(1)
uri = uri.format(uri = "{}@{}".format(f.username, instance)) uri = uri.format(uri = "{}@{}".format(f.username, instance))
r = requests.get(uri, headers={"Accept": "application/json"}) r = requests.get(uri, headers={"Accept": "application/json"}, timeout=10)
j = r.json() j = r.json()
if len(j['aliases']) == 1: #TODO: this is a hack on top of a hack, fix it if len(j['aliases']) == 1: #TODO: this is a hack on top of a hack, fix it
uri = j['aliases'][0] uri = j['aliases'][0]
else: else:
uri = j['aliases'][1] uri = j['aliases'][1]
uri = "{}/outbox?page=true&min_id={}".format(uri, last_toot) uri = "{}/outbox?page=true&min_id={}".format(uri, last_toot)
r = requests.get(uri) r = requests.get(uri, timeout=10)
j = r.json() j = r.json()
except Exception: except Exception:
print("oopsy woopsy!! we made a fucky wucky!!!\n(we're probably rate limited, please hang up and try again)") print("oopsy woopsy!! we made a fucky wucky!!!\n(we're probably rate limited, please hang up and try again)")
@ -208,7 +208,7 @@ for f in following:
except: except:
pass #ignore any toots that don't go into the DB pass #ignore any toots that don't go into the DB
# sys.exit(0) # sys.exit(0)
r = requests.get(j['prev']) r = requests.get(j['prev'], timeout=10)
j = r.json() j = r.json()
print('.', end='', flush=True) print('.', end='', flush=True)
print(" Done!") print(" Done!")