|
|
|
@ -9,7 +9,7 @@
|
|
|
|
|
|
|
|
|
|
from cProfile import label
|
|
|
|
|
import psycopg2 as psy# pip3 install types-psycopg2
|
|
|
|
|
import pandas as pand # pip3 install pandas
|
|
|
|
|
import pandas as pd # pip3 install pandas
|
|
|
|
|
import getpass
|
|
|
|
|
|
|
|
|
|
################# Debut Tips #################
|
|
|
|
@ -19,22 +19,30 @@ import getpass
|
|
|
|
|
|
|
|
|
|
################# Fin Tips #################
|
|
|
|
|
|
|
|
|
|
def insert_Country(connection, filename: str):
|
|
|
|
|
def insert_Status(connection, flow str):
|
|
|
|
|
cur = connection.cursor()
|
|
|
|
|
df = pand.DataFrame(pand.read_csv(filename)).dropna()
|
|
|
|
|
|
|
|
|
|
id_table=0
|
|
|
|
|
df = pd.DataFrame(pd.read_csv(filename)).dropna()
|
|
|
|
|
|
|
|
|
|
for row in df.itertuples():
|
|
|
|
|
for country in row.country_lastfm.split('; '):
|
|
|
|
|
id_table+=1
|
|
|
|
|
cur.execute("INSERT INTO Country VALUES (%s, %s) ON CONFLICT ON CONSTRAINT doublons_country DO NOTHING;",
|
|
|
|
|
(id_table,
|
|
|
|
|
str(country))
|
|
|
|
|
cur.execute("INSERT INTO Status VALUES (%s,%s,%s );",
|
|
|
|
|
(row.addresse,
|
|
|
|
|
row.type,
|
|
|
|
|
row.valeur)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
connection.commit()
|
|
|
|
|
cur.close()
|
|
|
|
|
|
|
|
|
|
def status_State(connection):
|
|
|
|
|
cur = connection.cursor()
|
|
|
|
|
pd.read_sql(''' SELECT adresse, type, valeur FROM Status'''
|
|
|
|
|
res = cur.fetchone()
|
|
|
|
|
return res
|
|
|
|
|
cur.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_tables(connection, filename):
|
|
|
|
|
cur = connection.cursor()
|
|
|
|
|
with open(filename) as f:
|
|
|
|
@ -52,10 +60,11 @@ if __name__ == '__main__':
|
|
|
|
|
db_name = 'dblodufour1'
|
|
|
|
|
db_user = input('Utilisateur : ')
|
|
|
|
|
if not db_user:
|
|
|
|
|
db_user = 'lodufour1'
|
|
|
|
|
db_user = 'ladufour1'
|
|
|
|
|
db_password = getpass('Mot de passe : ')
|
|
|
|
|
|
|
|
|
|
connection = psy.connect(host=db_host, database=db_name, user=db_user, password=db_password)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create_tables(connection, 'Table.sql')
|
|
|
|
|
connection.close()
|