jeudi 1 octobre 2015

convert output from sqlite from tuple to list

I am new to programming and am writing a simple script that will gather some information from a PC for forensic purposes. Some of the information I want is the Chrome history. Basically I need to read the data from the history sqlite database, perform a calculation to convert the time stamp to a human readable format, and then write the data to a CSV file. I have the following code:

connection = sqlite3.connect('c:\history')### need correct path
connection.text_factory = str
cur = connection.cursor()
output_file = open('chrome_history2.csv', 'wb')
csv_writer = csv.writer(output_file,)
headers = ('URL', 'Title', 'Visit Count', 'Last Visit')
csv_writer.writerow(headers)
epoch = datetime(1601, 1, 1)
for row in (cur.execute('select url, title, visit_count, last_visit_time from urls limit 10')): #selects data
        list(row) #convert to list - does not work
        url_time = epoch + timedelta(microseconds=row[3]) #calculates time
        row[3] = url_time #changes value in row to readable time
        csv_writer.writerow(row)
connection.close()

This code returns the error:

TypeError: 'tuple' object does not support item assignment

I understand that I can't manipulate the data in a tuple but I am explicitly converting each row to a list. Can anyone explain a) why list (row) does not work, and b) a better way to do it?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire