sncf: Fix some issues

This commit is contained in:
nemunaire 2022-08-21 02:12:53 +02:00
parent e40ae4db43
commit e6ad38d9ea

View File

@ -31,7 +31,7 @@ class SNCFAPI:
return Image.merge('RGBA', (r2,g2,b2,a))
def get_train_status(self, numero, date):
cache_file = self._cached_file % (numero, date.strftime("%Y-%m-%d"))
cache_file = self._cached_file % (int(numero), date.strftime("%Y-%m-%d"))
# Read the mod time
statinfo = None
try:
@ -41,7 +41,7 @@ class SNCFAPI:
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 + "/1.0/infoVoy/rechercherListeCirculations?numero=%d&dateCirculation=%s&codeZoneArret&typeHoraire=TEMPS_REEL" % (numero, date.strftime("%Y-%m-%d")), headers={'Authorization': "Basic " + self.auth})
req = urllib.request.Request(self.baseurl + "/1.0/infoVoy/rechercherListeCirculations?numero=%d&dateCirculation=%s&codeZoneArret&typeHoraire=TEMPS_REEL" % (int(numero), date.strftime("%Y-%m-%d")), headers={'Authorization': "Basic " + self.auth})
try:
with urllib.request.urlopen(req) as f:
with open(cache_file, 'wb') as fd:
@ -56,7 +56,10 @@ class SNCFAPI:
with open(cache_file) as f:
res = json.load(f)
return res["reponseRechercherListeCirculations"]["response"]["listeResultats"]["resultat"][0]["donnees"]["listeCirculations"]["circulation"][0]
try:
return res["reponseRechercherListeCirculations"]["reponse"]["listeResultats"]["resultat"][0]["donnees"]["listeCirculations"]["circulation"][0]
except:
return None
def get_weather(self, region):
cache_file = self._cached_file % (0, region)