generated from zenitheesc/new-zenith-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tabler.py
68 lines (53 loc) · 1.7 KB
/
Tabler.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import json
import os
import pandas
# Funcao para separacao dos jsons de acordo com data
def date_split(file_name):
file_type = '.json'
data_file = open(file_name + file_type)
data = json.load(data_file)
data_file.close()
data_sorted = []
num_days = 0
for item in data:
date_complete = item["datetime"]
date = date_complete[0:10]
has_place = False
for day in range(num_days):
if (date == data_sorted[day][0]):
data_sorted[day][1].append(item)
has_place = True
break
if (has_place == False):
num_days += 1
data_sorted.append([date, []])
data_sorted[num_days - 1][1].append(item)
for day in range(num_days):
new_file_name = data_sorted[day][0] + '_' + file_name + file_type
new_file = open(new_file_name, 'w')
json.dump(data_sorted[day][1], new_file, indent=4)
new_file.close()
def tabler(json_files, path):
for file_name in json_files:
data_file = open(file_name + '.json')
data = json.load(data_file)
data_file.close()
pandas.DataFrame(data).to_excel(file_name + '.xlsx')
# Aqui comeca a execucao
# Separa jsons de acordo com a data
path = os.getcwd()
files_list = os.listdir(path)
json_files = []
for item in files_list:
if (item.endswith('.json')):
json_files.append(item.split('.')[0])
for item in json_files:
date_split(item)
os.remove(path + '/' + item + '.json')
# Transforma em tabelas
files_list = os.listdir(path)
json_files = []
for item in files_list:
if (item.endswith('.json')):
json_files.append(item.split('.')[0])
tabler(json_files, path)