RATP: Use cache when API is not reachable
This commit is contained in:
parent
5acdf32ae7
commit
d7d9fe8a6d
@ -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})
|
||||
with urllib.request.urlopen(req) as f:
|
||||
with open(cache_file, 'wb') as fd:
|
||||
fd.write(f.read())
|
||||
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 = {}
|
||||
|
Loading…
Reference in New Issue
Block a user