sncf: Fix some issues
This commit is contained in:
parent
e40ae4db43
commit
e6ad38d9ea
@ -31,7 +31,7 @@ class SNCFAPI:
|
|||||||
return Image.merge('RGBA', (r2,g2,b2,a))
|
return Image.merge('RGBA', (r2,g2,b2,a))
|
||||||
|
|
||||||
def get_train_status(self, numero, date):
|
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
|
# Read the mod time
|
||||||
statinfo = None
|
statinfo = None
|
||||||
try:
|
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):
|
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
|
# 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:
|
try:
|
||||||
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:
|
||||||
@ -56,7 +56,10 @@ class SNCFAPI:
|
|||||||
with open(cache_file) as f:
|
with open(cache_file) as f:
|
||||||
res = json.load(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):
|
def get_weather(self, region):
|
||||||
cache_file = self._cached_file % (0, region)
|
cache_file = self._cached_file % (0, region)
|
||||||
|
Loading…
Reference in New Issue
Block a user