Jul-15-2018, 10:06 PM
(This post was last modified: Jul-15-2018, 10:14 PM by jimmyvegas29.)
So im trying to build a gui that display some unique timesheet data, i wont bore you with the end goal and why. One of the first things i need to do is be able to import the csv files that come out of the time management system into a seperate db. So after watching a ton of videos on python and sqlite i was thought i was ready to tackle this. I can get data to populate into the database, but whats happening is each list[] is going in as one big entry into each column, its not iterating through each item in the list. (see example picture)
![[Image: dboutput.png]](https://s15.postimg.cc/tg4fvmwbf/dboutput.png)
Here is a picture of the csv data
![[Image: csvdata.png]](https://s15.postimg.cc/4a3hp82vf/csvdata.png)
One of the things i need to do that is making it more complicated probably, is i do not need all the data in the csv, only certain columns, you can see in the code thats what im trying to call out.
Here is the code.
![[Image: dboutput.png]](https://s15.postimg.cc/tg4fvmwbf/dboutput.png)
Here is a picture of the csv data
![[Image: csvdata.png]](https://s15.postimg.cc/4a3hp82vf/csvdata.png)
One of the things i need to do that is making it more complicated probably, is i do not need all the data in the csv, only certain columns, you can see in the code thats what im trying to call out.
Here is the code.
import csv import sqlite3 jnumber = [] jdescription = [] sitenumber = [] travel = [] empcode = [] firstname = [] lastname = [] name = [] cindate = [] hours = [] city = [] state = [] pm = [] with open('C:\Python 3.5\Stuff\hours.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter=',') for row in readCSV: jnumbers = row[3] jdescriptions = row[4] sitenumbers = row[5] travels = row[6] empcodes = row[7] firstnames = row[8] lastnames = row[9] names = row[10] cindates = row[11] hourss = row[12] citys = row[13] states = row[14] pms = row[16] name.append(names) jnumber.append(jnumbers) sitenumber.append(sitenumbers) travel.append(travels) empcode.append(empcodes) firstname.append(firstnames) lastname.append(lastnames) cindate.append(cindates) hours.append(hourss) city.append(citys) state.append(states) pm.append(pms) conn = sqlite3.connect('testdb.db') c = conn.cursor() def create_table(): c.execute('CREATE TABLE IF NOT EXISTS testtable(jobnumber STRING, jdescription TEXT, sitenumber STRING, chargetype TEXT, employeecode INTEGER, firstname TEXT, lastname TEXT, fullname TEXT, clockindate DATE, hours DECIMAL(2), city TEXT, state TEXT, projectmanager TEXT)') conn.commit() def insert_data(): jnu = str(jnumber) jde = str(jdescription) sit = str(sitenumber) tra = str(travel) emp = str(empcode) fir = str(firstname) las = str(lastname) nam = str(name) cin = str(cindate) hou = str(hours) cit = str(city) sta = str(state) pjm = str(pm) c.execute("INSERT INTO testtable (jobnumber, jdescription, sitenumber, chargetype, employeecode, firstname, lastname, fullname, clockindate, hours, city, state, projectmanager) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (jnu, jde, sit, tra, emp, fir, las, nam, cin, hou, cit, sta, pjm)) conn.commit() for rows in range(1): insert_data() c.close() conn.close()Any help is much appreciated, I am new to Python/programming in general, but im using this project to learn. Its just seems to be very hard to search google for the right answers.