-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.py
54 lines (42 loc) · 1.33 KB
/
filter.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
#!/usr/bin/python
# encoding: utf-8
# -*- coding: utf-8 -*-
import json
import csv
from os import write
# 数据源 /Users/mac/Desktop/yyyy.json
# 输出的数据 /Users/mac/Desktop/res.csv
with open("/Users/mac/Desktop/yyyy.json",mode='r',encoding='utf-8') as input_file:
input_dict = json.load(input_file)
pageStats = input_dict['data']['pageStats']
monthStats = input_dict['data']['monthStats']
rr = {'pageExpenses':[]}
for item in pageStats:
for item2 in item['pageExpenses']:
for item3 in item2['expenses']:
d = item3['cts']
t = item3['cost']
c = item3['categoryName']
if 'remark' in item3:
r = item3['remark']
else:
r = ''
tile = {
'时间':d,
'金额':t,
'分类':c,
'备注':r,
'类型':'支出'
}
rr['pageExpenses'].append(tile)
output_json = json.dumps(rr, ensure_ascii=False)
data_file = open('/Users/mac/Desktop/res.csv', 'w')
csv_writer = csv.writer(data_file)
count = 0
for emp in rr['pageExpenses']:
if count == 0:
header = emp.keys()
csv_writer.writerow(header)
count += 1
csv_writer.writerow(emp.values())
data_file.close()