Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- import csv
- conn = sqlite3.connect('example.db')
- c = conn.cursor()
- # Lettura file FSCCDET
- with open("FSCCDET.csv", newline="") as filecsv:
- lettore = csv.reader(filecsv,delimiter = ";")
- print (" 1- *** FSCCDET.CSV ***")
- dati = [(linea[2] , linea[6] , linea[7]) for linea in lettore ]#if linea[2] =="143628"]
- for articolo in dati:
- print(f"{articolo[:3]}")
- # Crea Tabella
- c.execute('''CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)''')
- #c.execute('''CREATE TABLE sellout_2018 (codice_prodotto real , sellout_number real , offerta_number text , data_start text, data_stop text, quantita real, sconto real , valore_sellout , sell_out_pubblic_price real)''')
- c.execute('''CREATE TABLE sellout_2018 (codice_prodotto real , sellout_number real , offerta_number text , data_start real, data_stop real, quantita real, sconto real , valore_sellout , sell_out_pubblic_price real)''')
- # Inserisce una riga di dati
- #c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
- #c.execute("INSERT INTO sellout_2018 VALUES (144440,253,'O20180649P','2018-04-28','2018-04-29','','',100,3299)")
- purchases = [('2006-03-28','BUY','IBM',1000,45.00),
- ('2006-04-05','BUY','MSFT',1000,72.00),
- ('2006-04-06','SELL','IBM',500,53.00),
- ]
- c.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)',purchases)
- # Salva (commit) i cambiamenti
- conn.commit()
- for row in c.execute('SELECT * FROM stocks ORDER BY price'):
- print (row)
- purchases1 = [(dati[2],'',dati[4],dati[6],dati[7],'','','','')]
- #purchases1 = [(122222,253,'O2018555P','2018-05-07','2018-05-31',10.20,'',150.50,2000.70)]
- c.executemany('INSERT INTO sellout_2018 VALUES (?,?,?,?,?,?,?,?,?)',purchases1)
- conn.commit()
- for row in c.execute('SELECT * FROM sellout_2018 ORDER BY data_start'):
- print (row)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement