-
Notifications
You must be signed in to change notification settings - Fork 0
/
createCarDatabase.py
executable file
·57 lines (52 loc) · 1.97 KB
/
createCarDatabase.py
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
import sqlite3
def getCarDatabaseCursor():
connection = sqlite3.connect('car')
cursor = connection.cursor()
return connection, cursor
def createCarTable():
connection, cursor = getCarDatabaseCursor()
cursor.execute('drop table if exists car')
cursor.execute('''create table car(
carNum integer,
carName text,
horsepower integer,
acceleration float,
topSpeed integer,
torque integer,
RPM integer,
cost integer,
crashFactor float)'''
)
carList = open("carList.txt","r")
fileName = carList.readline()
while fileName !="":
listB =[]
fileName = fileName.rstrip("\r\n")
carBook = open('data/cars/' + fileName,"r")
carNum = 1
line = carBook.readline()
while line !="":
line = line.rstrip("\r\n")
listB.append(line[13:])
line = carBook.readline()
carName = listB[0]
horsepower = listB[1]
acceleration = listB[2]
topSpeed = listB[3]
torque = listB[4]
RPM = listB[5]
cost = listB[6]
crashFactor = listB[7]
carNum = 1
carBook.close()
carData = (carNum,carName,horsepower,acceleration,topSpeed,torque,RPM,cost,crashFactor)
cursor.execute('''insert into car(
carNum, carName, horsepower, acceleration, topSpeed, torque, RPM, cost,crashFactor)
values(?,?,?,?,?,?,?,?,?)''', carData
)
carNum += 1
connection.commit() # needed in order for changes to take effect
fileName = carList.readline()
connection.commit() # needed in order for changes to take effect
connection.close()
createCarTable()