-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseJSON.py
47 lines (37 loc) · 859 Bytes
/
parseJSON.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import tarfile
import sys
import io
import os
import gzip
import json
import re
import pickle as pk
import time
import ast
import HTMLParser
start = time.time()
fileName = './dailyArticles.txt'
f = open(fileName)
of = open('dailyCommentJSON.txt', 'w')
# for line in f:
# dic = json.loads(line)
# #print len(dic['results']['comments'])
# print dic.keys()
# break
fs = 0
for lines in f:
line = lines.rsplit('\t',2)[2]
try:
obj = json.loads(line)
json.dump(obj, fp=of)
of.write('\n')
except:
obj = json.loads(json.dumps(ast.literal_eval(line)))
json.dump(obj, fp=of)
of.write('\n')
# fs+=1
# print "{} files skipped".format(fs)
# continue
totalTime = time.time() - start
m, s = divmod(totalTime, 60)
print "Total Time Taken %d Min %d Seconds" % (m, s)