-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
73 lines (55 loc) · 2.29 KB
/
Copy pathdatabase.py
File metadata and controls
73 lines (55 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import mysql
from mysql import connector
from libs.fonct import *
import datetime
cnx = mysql.connector.connect(user="root", password="admin", host="127.0.0.1", database="infos")
db_name = "infos"
tables = {}
dates = []
mycursor = cnx.cursor()
dict = recuperer_fichiers()
def creer_Table_Infos():
mycursor.execute("CREATE TABLE Infos (id int primary key not null auto_increment,"
" Date date, Nom varchar(255), Type char(255))")
def creer_Table_Comparaison():
mycursor.execute("CREATE TABLE Comparaison (id int primary key not null auto_increment,"
" Date date, Total Integer(100))")
def remplir_table_infos():
sqlFormula = "INSERT INTO Infos (Date, Nom, Type) VALUES (%s, %s, %s)"
for cle, value in dicti.items():
for i in value:
information = (datetime.datetime.today().strftime('%Y-%m-%d'), i, cle)
mycursor.execute(sqlFormula, information)
cnx.commit()
def remplir_Table_Comparaison():
sqlFormula = "INSERT INTO Comparaison (Date, Total) VALUES(%s, %s)"
information = (datetime.datetime.today().strftime('%Y-%m-%d'), compter())
mycursor.execute(sqlFormula, information)
cnx.commit()
def compter():
total = 0
mycursor.execute("select distinct nom from Infos")
for i in mycursor.fetchall():
total += 1
return total
def recuperer_date():
mycursor.execute("select distinct Date from comparaison")
for i in mycursor.fetchall():
dates.append(i)
return dates
def comparaison(date):
"""
:param date:
:return:
"""
mycursor.execute('SELECT Max(Total) FROM comparaison WHERE Date LIKE \'%' + date + '%\'')
return mycursor.fetchone()
def result_comparaison(date: str) -> str:
if date == datetime.datetime.today().strftime("%Y-%m-%d"):
return "A ce jour, vous possedez {} fichiers dans votre dossier de téléchargements".format(compter())
else:
mycursor.execute('SELECT Max(Total) FROM comparaison WHERE Date LIKE Date(Now())')
total_today = mycursor.fetchone()[0]
difference = total_today - comparaison(date)[0]
return "Depuis le {}, vous avez téléchargé {} nouveaux fichier(s).\n Ainsi vous êtes à {} fichiers dans votre "\
"dossier de téléchargements".format(date, difference, compter())