Skip to content

Instantly share code, notes, and snippets.

@ikuwow
Created December 15, 2016 00:42
Show Gist options
  • Save ikuwow/7a6f4bced69ff6d4f7d5ea48390df461 to your computer and use it in GitHub Desktop.
Save ikuwow/7a6f4bced69ff6d4f7d5ea48390df461 to your computer and use it in GitHub Desktop.
jsons2csv.py
# -*- coding: utf-8 -*-
import json, codecs, os
srcdir = 'perdate/'
destdir = 'perdate_tsv/'
if not os.path.exists(destdir):
os.mkdir(destdir)
for month in range(12,13):
month = '%02d' % month
print month
os.mkdir(destdir + month)
for date in range(1,31):
date = '%02d' % date
print date
jsonFile = open(srcdir + month + '/' + date + '.jsons', 'r')
output = open(destdir + month + '/' + date + '.tsv', 'w')
line = jsonFile.readline()
while line:
data = json.loads(line)
jsonData = data['textPayload'].encode('utf-8')
output.write(jsonData + "\n")
line = jsonFile.readline()
jsonFile.close
output.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment