Last active
August 9, 2018 12:34
-
-
Save MatthewWilkes/e97dfc2b65c78c0e346c07c2c3dde462 to your computer and use it in GitHub Desktop.
Data update script for GU
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 sys | |
filename = sys.argv[1] | |
import csv | |
import StringIO | |
import subprocess | |
import zipfile | |
data = zipfile.ZipFile(filename, mode='r') | |
info_file = data.open('data/info.csv') | |
lines = [] | |
for line in csv.DictReader(info_file): | |
if line['type'] == 'state': | |
line['details'] = line['contents'] | |
lines.append(line) | |
info_file.close() | |
info_data = StringIO.StringIO() | |
csv_file = csv.DictWriter(info_data, fieldnames=[ | |
'id', | |
'creation_time', | |
'property1', | |
'property2', | |
'property3', | |
'property4', | |
'property5', | |
'failed', | |
'time_of_death', | |
'details', | |
'type', | |
'origin_id', | |
'network_id', | |
'contents' | |
]) | |
csv_file.writeheader() | |
csv_file.writerows(lines) | |
data.close() | |
cmd=['zip', '-d', filename, 'data/info.csv'] | |
subprocess.check_call(cmd) | |
data = zipfile.ZipFile(filename, mode='a') | |
data.writestr('data/info.csv', info_data.getvalue()) | |
data.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment