Created
January 14, 2016 09:04
-
-
Save phoenleo/5a0a2f7e22528e5002d8 to your computer and use it in GitHub Desktop.
Convert Localization CSV to JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| import json | |
| import collections | |
| csvfile = open('file.csv', 'r') | |
| def isKeyEmptyOrComment (stringKey): | |
| if not stringKey: return True | |
| if stringKey[0] == "@": return True | |
| return False | |
| reader = csv.reader(csvfile) | |
| ncol = len(next(reader)) | |
| csvfile.seek(0) | |
| headers = reader.next() | |
| csvfile.seek(0) | |
| next(reader) | |
| for col in range(1, ncol): | |
| mydict = collections.OrderedDict() | |
| jsonfile = open(headers[col] +'.json', 'w') | |
| for rows in reader: | |
| if isKeyEmptyOrComment(rows[0]): continue | |
| mydict[rows[0]] = rows[col] | |
| json.dump(mydict, jsonfile) | |
| csvfile.seek(0) | |
| next(reader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment