Log exceptions

This commit is contained in:
nemunaire 2023-01-16 13:48:41 +01:00
parent 9d625c87ee
commit 287c4ac349
3 changed files with 13 additions and 14 deletions

View File

@ -2,6 +2,7 @@ from collections.abc import Iterable
from datetime import date, datetime, timedelta, timezone from datetime import date, datetime, timedelta, timezone
from functools import reduce from functools import reduce
import hashlib import hashlib
import logging
import re import re
import time import time
import urllib.error import urllib.error
@ -47,11 +48,9 @@ class IcalModule:
with open(cache_file, 'wb') as fd: with open(cache_file, 'wb') as fd:
fd.write(c.read()) fd.write(c.read())
except ConnectionResetError as e: except ConnectionResetError as e:
print(e) logging.exception(e)
pass
except urllib.error.URLError as e: except urllib.error.URLError as e:
print(e) logging.exception(e)
pass
with open(cache_file) as c: with open(cache_file) as c:
ecal = Calendar.from_ical(c.read()) ecal = Calendar.from_ical(c.read())

View File

@ -1,6 +1,7 @@
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
import hashlib import hashlib
import json import json
import logging
import os import os
import urllib.parse import urllib.parse
import urllib.request import urllib.request
@ -97,12 +98,12 @@ class IDFMAPI:
with urllib.request.urlopen(req) as f: with urllib.request.urlopen(req) as f:
with open(cache_file, 'wb') as fd: with open(cache_file, 'wb') as fd:
fd.write(f.read()) fd.write(f.read())
except ConnectionResetError: except ConnectionResetError as e:
pass logging.exception(e)
except urllib.error.URLError: except urllib.error.URLError as e:
pass logging.exception(e)
except urllib.error.HTTPError: except urllib.error.HTTPError as e:
pass logging.exception(e)
with open(cache_file) as f: with open(cache_file) as f:
res = json.load(f) res = json.load(f)

View File

@ -65,7 +65,9 @@ class SNCFAPI:
pass pass
if statinfo is None or datetime.fromtimestamp(statinfo.st_mtime, tz=timezone.utc) + timedelta(minutes=self.max_cache_timeout) < datetime.now(tz=timezone.utc): if statinfo is None or datetime.fromtimestamp(statinfo.st_mtime, tz=timezone.utc) + timedelta(minutes=self.max_cache_timeout) < datetime.now(tz=timezone.utc):
raise Exception("File too old") print(self.baseurl + "/1.0/infoVoy/rechercherListeCirculations?numero=%d&dateCirculation=%s&codeZoneArret&typeHoraire=TEMPS_REEL" % (int(numero), date.strftime("%Y-%m-%d")))
logging.exception(Exception("File too old to predict SNCF issue"))
return None
# Retrieve cached data # Retrieve cached data
res = {} res = {}
@ -101,13 +103,10 @@ class SNCFAPI:
fd.write(f.read()) fd.write(f.read())
except ConnectionResetError as e: except ConnectionResetError as e:
logging.exception(e) logging.exception(e)
pass
except urllib.error.URLError as e: except urllib.error.URLError as e:
logging.exception(e) logging.exception(e)
pass
except TimeoutError as e: except TimeoutError as e:
logging.exception(e) logging.exception(e)
pass
try: try:
statinfo = os.stat(cache_file) statinfo = os.stat(cache_file)