Le mirroring des dépôts vers Github est maintenant natif dans Gitlab (et donc Framagit). Merci de passer à la fonction native pour que nous puissions couper notre solution maison. Détails sur https://docs.gitlab.com/ee/workflow/repository_mirroring.html#pushing-to-a-remote-repository (pensez à supprimer le webhook de notre solution maison).

Commit f5efb428 by JonathanMM

Ajout de stationId, récupération de ce dernier et création d'un script de mise à…

Ajout de stationId, récupération de ce dernier et création d'un script de mise à jour du last refresh
parent 6c4e164e
import pymysql, urllib.request, json, os
from config import getMysqlConnection
mysql = getMysqlConnection()
#On récupère toutes les stations sans insee
requete = mysql.cursor()
requete.execute('SELECT code, latitude, longitude, name FROM stations WHERE stationId IS NULL')
stations = requete.fetchall()
tmpFileName = 'gbfsStation.json'
urllib.request.urlretrieve("https://velib-metropole-opendata.smoove.pro/opendata/Velib_Metropole/station_information.json", tmpFileName)
data = json.load(open(tmpFileName))
for station in stations:
codeStation = station[0]
latitude = float(station[1])
longitude = float(station[2])
for stat in data['data']['stations']:
if abs(stat['lat'] - latitude) < 0.00002 and abs(stat['lon'] - longitude) < 0.00002:
requete = mysql.cursor()
requete.execute('UPDATE stations SET stationId = '+str(stat['station_id'])+' WHERE code = '+str(codeStation))
mysql.close()
os.remove(tmpFileName)
\ No newline at end of file
import urllib.request, json, os, pymysql
from datetime import datetime
from config import getMysqlConnection, getURLVelib
from adresseLib import getAdresse, getInsee
def getStationIdByLatLong(latitude, longitude):
tmpFileName = 'gbfsStation.json'
urllib.request.urlretrieve("https://velib-metropole-opendata.smoove.pro/opendata/Velib_Metropole/station_information.json", tmpFileName)
data = json.load(open(tmpFileName))
for stat in data['data']['stations']:
if abs(stat['lat'] - latitude) < 0.00002 and abs(stat['lon'] - longitude) < 0.00002:
return stat['station_id']
os.remove(tmpFileName)
def getGBFSData():
tmpFileName = 'gbfsStatus.json'
urllib.request.urlretrieve("https://velib-metropole-opendata.smoove.pro/opendata/Velib_Metropole/station_status.json", tmpFileName)
data = json.load(open(tmpFileName))
os.remove(tmpFileName)
return data['data']['stations']
\ No newline at end of file
import pymysql
from config import getMysqlConnection
from gbfsLib import getGBFSData
import datetime
mysql = getMysqlConnection()
data = getGBFSData()
for station in data:
lastRefresh = datetime.datetime.fromtimestamp(int(station['last_reported']), datetime.timezone.utc)
stationId = station['station_id']
requete = mysql.cursor()
requete.execute('UPDATE stations SET lastRefresh = "'+lastRefresh.strftime("%Y-%m-%d %H:%M:%S")+'" WHERE stationId = '+str(stationId))
\ No newline at end of file
......@@ -2,6 +2,7 @@ import urllib.request, json, os, pymysql
from datetime import datetime
from config import getMysqlConnection, getURLVelib
from adresseLib import getAdresse, getInsee
from gbfsLib import getStationIdByLatLong
def getAllStation():
mysql = getMysqlConnection()
......@@ -51,9 +52,12 @@ def getAllStation():
strDateOuverture = 'NULL'
else:
strDateOuverture = 'CURDATE()'
#On récupère également le stationId des données GTFS
stationId = getStationIdByLatLong(latitude, longitude)
requete = mysql.cursor()
requete.execute('INSERT INTO stations (code, name, longitude, latitude, type, dateOuverture, adresse, insee) VALUES \
('+str(codeStation)+', "'+str(infoStation['name'])+'", '+str(longitude)+', '+str(latitude)+', "'+str(infoStation['type'])+'", '+strDateOuverture+', "'+getAdresse(latitude, longitude)+'", '+str(getInsee(codeStation))+')')
requete.execute('INSERT INTO stations (code, name, longitude, latitude, type, dateOuverture, adresse, insee, stationId) VALUES \
('+str(codeStation)+', "'+str(infoStation['name'])+'", '+str(longitude)+', '+str(latitude)+', "'+str(infoStation['type'])+'", '+strDateOuverture+', "'+getAdresse(latitude, longitude)+'", '+str(getInsee(codeStation))+', '+str(stationId)+')')
stations.append(codeStation)
nbBike = int(etatStation['nbBike'])
......
......@@ -102,7 +102,9 @@ CREATE TABLE `stations` (
`type` varchar(256) NOT NULL,
`dateOuverture` date DEFAULT NULL,
`adresse` text,
`insee` int(5) DEFAULT NULL
`insee` int(5) DEFAULT NULL,
`stationId` int(11) DEFAULT NULL,
`lastRefresh` datetime DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
......@@ -173,6 +175,7 @@ ALTER TABLE `signalement`
--
ALTER TABLE `stations`
ADD PRIMARY KEY (`code`),
ADD UNIQUE KEY `stationId` (`stationId`),
ADD KEY `insee` (`insee`);
--
......
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