From b13813f96822ed7de314b6dd417831de8a641134 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 31 Oct 2014 21:45:51 +0100 Subject: * revised and reorganized dump scripts --- dumps/compile.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 dumps/compile.py (limited to 'dumps/compile.py') 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) + -- cgit v1.2.3