Created
January 17, 2018 10:02
-
-
Save yukpiz/f2b6aa5a81c9d70a073908c1e712c363 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import datetime | |
import csv | |
import codecs | |
d = datetime.datetime(2017, 9, 1, 0, 0, 0, 0) | |
rows = [] | |
while True: | |
fname = d.strftime("%Y-%m-%d.json") | |
try: | |
f = open(fname) | |
data = json.load(f) | |
for m in data: | |
row = [] | |
row.append(str(m["user"])) | |
row.append(m["text"]) | |
row.append(str(m["ts"])) | |
print("%s,%s,%s" % (row[0],row[1].replace("\n", "\\n"),row[2])) | |
f.close() | |
except: | |
pass | |
d = d + datetime.timedelta(days=1) | |
if fname == "2018-01-16.json": | |
break | |
f = open('messages.csv', 'w') | |
writer = csv.writer(f, lineterminator='\n') | |
writer.writerows(rows) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment