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
| def init_data_base(path):
file = re.split("/", path)[-1] #on récupère le nom de fichier de path
if file not in os.listdir('/home/majid/Bureau/RETAILSCODES/RetailsStores'):
print("Création de la base de données")
database = sqlite3.connect(path)
cursor = database.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS database(
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
epc TEXT,
famille TEXT,
sous-famille TEXT,
libelle TEXT,
rssi INTEGER,
antenna INTEGER,
date_entree TEXT);
"""
)
cursor.execute("""DELETE FROM database""")
else :
print("Base de données existante !")
database = sqlite3.connect('/home/majid/Bureau/RETAILSCODES/RetailsStores/database.db')
cursor = database.cursor()
print("Fin d'initalisation de la base de données")
return database, cursor
def add_article(database, cursor, article_info):
print("Debut ajout article à la base données")
EPC, FAMILLE, SOUS-FAMILLE, LIBELLE, RSSI, ANTENNA = article_info[0], article_info[1], article_info[2], article_info[3], article_info[4], article_info[5]
now = datetime.datetime.now()
DATE_ENTREE = str(now.year)+"_"+str(now.month)+"_"+str(now.day)+"_"+str(now.hour)+"_"+str(now.minute)
cursor.executemany(''' INSERT INTO database (epc, famille, sous-famille, libelle, rssi, antenna, date_entree) VALUES (?,?,?,?,?,?,?)''', [(EPC, FAMILLE, SOUS-FAMILLE, LIBELLE, RSSI, ANTENNA, DATE_ENTREE,)])
database.commit()
print("Article ajouté à la base de données")
return |
Partager