diff options
author | emkael <emkael@tlen.pl> | 2014-10-31 21:45:51 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2014-10-31 21:45:51 +0100 |
commit | b13813f96822ed7de314b6dd417831de8a641134 (patch) | |
tree | 0dc65154fd9531a31732e422619bb5b7aaebe775 /dumps/compile.py | |
parent | ae189fadac1f56b2c10f2a5d11bad99980a8fd46 (diff) |
* revised and reorganized dump scripts
Diffstat (limited to 'dumps/compile.py')
-rw-r--r-- | dumps/compile.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/dumps/compile.py b/dumps/compile.py new file mode 100644 index 0000000..d87e154 --- /dev/null +++ b/dumps/compile.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import csv +import string +from sys import argv + +def compile(files): + headers = set() + values = [] + writer = csv.writer(open('races.csv', 'w')) + race_id = 0 + for path in files: + try: + with open(path, 'r') as csvfile: + reader = csv.reader(csvfile) + header = next(reader) + headers = set(headers | set(header)) + for row in reader: + data = {} + i = 0 + for cell in row: + data[header[i]] = cell + data['Race'] = race_id + i += 1 + values.append(data) + writer.writerow([race_id, path, '', '', '']) + race_id += 1 + except IOError: + pass + headers.add('Race') + writer = csv.writer(open('compiled.csv', 'w')) + writer.writerow(list(headers)) + for row in values: + csvrow = [] + for name in headers: + if name in row: + csvrow.append(row[name]) + else: + csvrow.append('') + writer.writerow(csvrow) + |