From 0060cf311d4df1c9f65ad0bbef02fd752deabfa3 Mon Sep 17 00:00:00 2001 From: Sumpfork Date: Fri, 20 Nov 2015 17:00:36 -0800 Subject: [PATCH] Bring over refactoring and start of unit tests --- convert_csv.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 convert_csv.py diff --git a/convert_csv.py b/convert_csv.py new file mode 100644 index 00000000..2db4998d --- /dev/null +++ b/convert_csv.py @@ -0,0 +1,33 @@ +# coding=utf-8 +import csv +import sys +import json +import chardet + +converted = [] + +typemap = {'Aktion': 'Action', + 'Geld': 'Treasure', + 'Fluch': 'Curse', + 'Punkte': 'Victory', + 'Reaktion': 'Reaction', + 'Angriff': 'Attack', + 'Dauer': 'Duration'} + +with open(sys.argv[1], 'U') as csvfile: + reader = csv.DictReader(csvfile) + for row in reader: + if not ''.join(row.itervalues()): + continue + # row = {k: v.decode('ISO-8859-2').encode('utf-8') if type(v) == str else v for k, v in row.iteritems()} + print chardet.detect(row['Kartentext']) + print row['Kartentext'] + converted_row = {'name': row['Kartenname'], + 'cost': row['Kosten'], + 'cardset': row['Edition'], + 'description': row['Kartentext'], + 'extra': row['Lange Erklärung'], + 'types': [typemap[t.strip()] for t in row['Typ'].split('/')], + 'potcost': row.get('potcost', 0)} + converted.append(converted_row) +json.dump(converted, open(sys.argv[2], 'wb'), indent=True)