Created
May 15, 2018 18:41
-
-
Save maltzsama/ff57553bceb5aa48ef572d5cb90ab7d3 to your computer and use it in GitHub Desktop.
parser try
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
#!/usr/bin/env python | |
import json | |
def json_decode(info = None, table = None, visitorId = None): | |
# print table | |
table_dict = {} | |
keys = info.keys() | |
for k in keys: | |
if type(info[k]) == dict: | |
json_decode(info[k], k, visitorId) | |
elif type(info[k]) == list: | |
for el in info[k]: | |
json_decode(el, k, visitorId) | |
else: | |
table_dict[k] = info[k] | |
with open('table/' + table + '.txt', "a+") as f: | |
keys = table_dict.keys() | |
for k in keys: | |
f.write(k + ':' + str( table_dict[k]) + ' \n') | |
with open('santander-PJ.json') as f: | |
data = json.load(f) | |
x = {} | |
for n in data: | |
if 'fullVisitorId' in n: | |
visitorId = n['fullVisitorId'] | |
x = json_decode(n, table = 'main', visitorId = visitorId) | |
print x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment