Commit e2d84317 authored by JonathanMM's avatar JonathanMM

Création d'un système d'import de dump (partie data)

parent fbff03d0
......@@ -208,4 +208,28 @@ def creerDumpConso(dateDebut):
conn.commit()
#Et on ferme le fichier
c.close()
\ No newline at end of file
c.close()
def importerDumpData(adresseDump):
sqlite = sqlite3.connect(adresseDump)
mysql = getMysqlConnection()
importerTable("stations", mysql, sqlite)
importerTable("status", mysql, sqlite)
importerTable("statusConso", mysql, sqlite)
def importerTable(nomTable, mysql, sqlite):
#On récupère la liste des champs de stations
c = sqlite.cursor()
requete = c.execute("pragma table_info(" + nomTable + ")")
fields = requete.fetchall()
nomFields = []
for field in fields:
nomFields.append(field[1])
#On récupère les données
cDump = sqlite.cursor()
requete = cDump.execute("SELECT "+', '.join(nomFields)+" FROM " + nomTable)
valeurs = requete.fetchall()
for valeur in valeurs:
c = mysql.cursor()
c.execute("INSERT INTO " + nomTable + " (" + ", ".join(nomFields) + ") VALUES (" + ", ".join(list(map(val,valeur))) + ")")
\ No newline at end of file
from dumpLib import importerDumpData
importerDumpData('../dump/2018-01-07-data.db')
\ No newline at end of file
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