Created
December 15, 2016 00:42
-
-
Save ikuwow/7a6f4bced69ff6d4f7d5ea48390df461 to your computer and use it in GitHub Desktop.
jsons2csv.py
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
# -*- 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