diff options
author | emkael <emkael@tlen.pl> | 2014-10-06 15:51:30 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2014-10-06 15:51:30 +0200 |
commit | 8249784c586a088c09598305fd408f376aad26fb (patch) | |
tree | 21a894b662a4c5bc4271d146bb6a3f38e715c236 /import-csv.py |
* initial commit
Diffstat (limited to 'import-csv.py')
-rw-r--r-- | import-csv.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/import-csv.py b/import-csv.py new file mode 100644 index 0000000..de0eb7a --- /dev/null +++ b/import-csv.py @@ -0,0 +1,27 @@ +from f1elo.db import Session, find_driver +from f1elo.model import * +import sys + +session = Session() + +import csv +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 = find_driver(row[4].strip(), row[3].strip(), session) + entry.drivers.append(driver) + elif len(row) == 2: + driver = find_driver(row[1].strip(), row[0].strip(), session) + entry.drivers.append(driver) + else: + print row + +session.commit() |