Skip to content

Commit e887385

Browse files
committed
logic for proper JSON blob
1 parent cbee373 commit e887385

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

middleware/exporter.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,21 @@ def go():
6868
# init buffer
6969
buff = io.BytesIO()
7070

71-
# retrieve output from sz into buff
71+
# Retrieve output from sz into buff
72+
# sz will export JSONL lines; we add the chars necessary to make
73+
# the output as a whole be a single JSON blob.
7274
try:
7375
export_handle = sz_eng.export_json_entity_report(EXPORT_FLAGS)
76+
buff.write('['.encode('utf-8'))
7477
while 1:
7578
chunk = sz_eng.fetch_next(export_handle)
7679
if not chunk:
7780
break
7881
buff.write(chunk.encode('utf-8'))
82+
buff.write(','.encode('utf-8'))
7983
sz_eng.close_export_report(export_handle)
84+
buff.seek(-1, os.SEEK_CUR) # toss out last comma
85+
buff.write(']'.encode('utf-8'))
8086
except sz.SzError as err:
8187
print(err)
8288

@@ -114,11 +120,14 @@ def upload_test_file():
114120
print("SUCCESSFUL")
115121

116122
def get_file():
117-
key = 'output-1757986924786.json'
123+
key = 'output-1758036760013.json'
118124
print('Grabbing file...')
119125
s3 = make_s3_client()
120126
resp = s3.download_file(S3_BUCKET, key, '/tmp/'+key)
121127
print(resp)
122128
print('done grabbing file.')
123129
#f = open('/tmp/'+key)
124130
#print(f.readlines())
131+
132+
#upload_test_file()
133+
#get_file()

0 commit comments

Comments
 (0)