forked from emkael/elof1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-csv.py
More file actions
28 lines (24 loc) · 741 Bytes
/
import-csv.py
File metadata and controls
28 lines (24 loc) · 741 Bytes
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
import csv
import sys
from f1elo.db import Session
from f1elo.model import *
session = Session()
with open(sys.argv[1]) as f:
reader = csv.reader(f)
for row in reader:
driver = None
if len(row) == 6:
entry = Entry()
entry._race = row[0]
entry.result = row[1]
entry.car_no = row[2]
entry.result_group = row[5]
session.add(entry)
driver = Driver.fetch(row[4].strip(), row[3].strip(), session)
entry.drivers.append(driver)
elif len(row) == 2:
driver = Driver.fetch(row[1].strip(), row[0].strip(), session)
entry.drivers.append(driver)
else:
print row
session.commit()