RATP: Use cache when API is not reachable

This commit is contained in:
nemunaire 2022-08-14 20:27:54 +02:00
parent 5acdf32ae7
commit d7d9fe8a6d

View File

@ -83,9 +83,12 @@ class IDFMAPI:
if statinfo is None or datetime.fromtimestamp(statinfo.st_mtime, tz=timezone.utc) + timedelta(minutes=self.cache_time) < datetime.now(tz=timezone.utc):
# Do the request and save it
req = urllib.request.Request(self.baseurl + "/general-message?LineRef=STIF:Line::" + IDFMAPI.lines[mode][line] + ":", headers={'apikey': self.apikey})
try:
with urllib.request.urlopen(req) as f:
with open(cache_file, 'wb') as fd:
fd.write(f.read())
except ConnectionResetError:
pass
# Retrieve cached data
res = {}