From 80f61ced22080281a4c1c2d714291c95268c41b9 Mon Sep 17 00:00:00 2001 From: Louis DUFOUR Date: Fri, 3 Mar 2023 14:25:57 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'src/Main.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Main.py b/src/Main.py index 0177bf4..fbea8fd 100644 --- a/src/Main.py +++ b/src/Main.py @@ -19,6 +19,22 @@ import getpass ################# Fin Tips ################# +def insert_Country(connection, filename: str): + cur = connection.cursor() + df = pand.DataFrame(pand.read_csv(filename)).dropna() + + id_table=0 + 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)) + ) + + connection.commit() + cur.close() + def create_tables(connection, filename): cur = connection.cursor() with open(filename) as f: