|
|
@ -8,11 +8,9 @@
|
|
|
|
# ========================================================================
|
|
|
|
# ========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
from cProfile import label
|
|
|
|
from cProfile import label
|
|
|
|
from sys import api_version
|
|
|
|
import psycopg2 as psy# pip3 install types-psycopg2
|
|
|
|
import psycopg2 # pip3 install types-psycopg2
|
|
|
|
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
import pandas as pand # pip3 install pandas
|
|
|
|
import pandas as pand # pip3 install pandas
|
|
|
|
from getpass import getpass
|
|
|
|
import getpass
|
|
|
|
|
|
|
|
|
|
|
|
################# Debut Tips #################
|
|
|
|
################# Debut Tips #################
|
|
|
|
|
|
|
|
|
|
|
@ -21,26 +19,18 @@ from getpass import getpass
|
|
|
|
|
|
|
|
|
|
|
|
################# Fin Tips #################
|
|
|
|
################# Fin Tips #################
|
|
|
|
|
|
|
|
|
|
|
|
def create_tables(connection, filename: str):
|
|
|
|
def create_tables(connection, filename):
|
|
|
|
cur = connection.cursor()
|
|
|
|
cur = connection.cursor()
|
|
|
|
with open(filename) as f:
|
|
|
|
with open(filename) as f:
|
|
|
|
cur.execute(f.read())
|
|
|
|
cur.execute(f.read())
|
|
|
|
connection.commit()
|
|
|
|
connection.commit()
|
|
|
|
cur.close()
|
|
|
|
cur.close()
|
|
|
|
|
|
|
|
|
|
|
|
def Methode1(connection):
|
|
|
|
|
|
|
|
"""Exemple request"""
|
|
|
|
|
|
|
|
df = pand.read_sql("SELECT name_country, nbmusic FROM Top10MusiquesParPays", con=connection)
|
|
|
|
|
|
|
|
fig = df.plot.bar(x='name_country', y='nbmusic', legend=False, rot=0)
|
|
|
|
|
|
|
|
fig.set_xlabel('Country')
|
|
|
|
|
|
|
|
fig.set_ylabel('Music count')
|
|
|
|
|
|
|
|
fig.bar_label(fig.containers[0]) # Show values
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Lors de l'execution le main s'exectute et en plus si on l'import autre part cela n'executera pas le code
|
|
|
|
# Lors de l'execution le main s'exectute et en plus si on l'import autre part cela n'executera pas le code
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
db_host = input('Nom d\'hôte : ')
|
|
|
|
db_host = input('Nom d\'hôte : ')
|
|
|
|
if not db_host:
|
|
|
|
if not db_host:
|
|
|
|
db_host = 'berlin'
|
|
|
|
db_host = 'londres'
|
|
|
|
db_name = input('Nom de la base de données : ')
|
|
|
|
db_name = input('Nom de la base de données : ')
|
|
|
|
if not db_name:
|
|
|
|
if not db_name:
|
|
|
|
db_name = 'dblodufour1'
|
|
|
|
db_name = 'dblodufour1'
|
|
|
@ -49,8 +39,7 @@ if __name__ == '__main__':
|
|
|
|
db_user = 'lodufour1'
|
|
|
|
db_user = 'lodufour1'
|
|
|
|
db_password = getpass('Mot de passe : ')
|
|
|
|
db_password = getpass('Mot de passe : ')
|
|
|
|
|
|
|
|
|
|
|
|
connection = psycopg2.connect(host=db_host, port=5432, database=db_name, user=db_user, password=db_password)
|
|
|
|
connection = psy.connect(host=db_host, database=db_name, user=db_user, password=db_password)
|
|
|
|
|
|
|
|
|
|
|
|
#create_tables(connection, 'Table.sql')
|
|
|
|
create_tables(connection, 'Table.sql')
|
|
|
|
#Methode1(connection)
|
|
|
|
|
|
|
|
connection.close()
|
|
|
|
connection.close()
|