diff options
author | Jordan <me@jordan.im> | 2021-12-24 15:36:51 -0700 |
---|---|---|
committer | Jordan <me@jordan.im> | 2021-12-24 15:36:51 -0700 |
commit | fefe88f62bb275452aee008b5345a606811b2dc3 (patch) | |
tree | a4be7706f4bb5f61dcd0f0815c3b9a892e1531d3 /allium/lib/relays.py | |
parent | 916fa2986c4c840aed3103e3da9406b2d9aae507 (diff) | |
download | allium-fefe88f62bb275452aee008b5345a606811b2dc3.tar.gz allium-fefe88f62bb275452aee008b5345a606811b2dc3.zip |
relays: die peacefully w/ HTTP 304 (no onionoo update)
Diffstat (limited to 'allium/lib/relays.py')
-rw-r--r-- | allium/lib/relays.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/allium/lib/relays.py b/allium/lib/relays.py index 70ada47..378e8dc 100644 --- a/allium/lib/relays.py +++ b/allium/lib/relays.py @@ -27,6 +27,8 @@ class Relays(): self.onionoo_url = onionoo_url self.ts_file = os.path.join(os.path.dirname(ABS_PATH), "timestamp") self.json = self._fetch_onionoo_details() + if self.json == None: + return self.timestamp = self._write_timestamp() self._fix_missing_observed_bandwidth() @@ -48,7 +50,14 @@ class Relays(): else: conn = urllib.request.Request(self.onionoo_url) - api_response = urllib.request.urlopen(conn).read() + try: + api_response = urllib.request.urlopen(conn).read() + except urllib.error.HTTPError as err: + if err.code == 304: + print("no onionoo update since last run, dying peacefully...") + return + else: + raise(err) return json.loads(api_response.decode('utf-8')) |