Commit e18c25b6 authored by JonathanMM's avatar JonathanMM

Fix #7 Données renvoyé pourri par velib => ignoré

parent ec09554f
...@@ -3,12 +3,17 @@ from datetime import datetime ...@@ -3,12 +3,17 @@ from datetime import datetime
from config import getMysqlConnection, getURLVelib from config import getMysqlConnection, getURLVelib
from adresseLib import getAdresse, getInsee from adresseLib import getAdresse, getInsee
from gbfsLib import getStationIdByLatLong from gbfsLib import getStationIdByLatLong
import hashlib, time
def val(valeur): def val(valeur):
if valeur is None: if valeur is None:
return 'NULL' return 'NULL'
return '"'+str(valeur)+'"' return '"'+str(valeur)+'"'
def fichierEnBinaire(file):
with file:
return file.read()
def getAllStation(): def getAllStation():
mysql = getMysqlConnection() mysql = getMysqlConnection()
...@@ -39,8 +44,24 @@ def getAllStation(): ...@@ -39,8 +44,24 @@ def getAllStation():
urlVelib = getURLVelib() urlVelib = getURLVelib()
tmpFileName = 'detailsStations.json' tmpFileName = 'detailsStations.json'
urllib.request.urlretrieve(urlVelib, tmpFileName) nbEssai = 0
data = json.load(open(tmpFileName)) fichierOk = False
while nbEssai < 3 and not fichierOk:
urllib.request.urlretrieve(urlVelib, tmpFileName)
dataBrut = open(tmpFileName)
#On regarde si ce n'est pas le md5 corrompu !
valeurMD5 = hashlib.md5(fichierEnBinaire(open(tmpFileName, 'rb'))).hexdigest()
fichierOk = valeurMD5 != 'c746fec461216aa3a67602b879dafa6c'
nbEssai += 1
if not fichierOk:
os.remove(tmpFileName)
time.sleep(10)
if not fichierOk: #On n'a trouvé de valeurs correctes :(
return False
data = json.load(dataBrut)
for etatStation in data: for etatStation in data:
infoStation = etatStation['station'] infoStation = etatStation['station']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment