-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdata_handler.py
55 lines (49 loc) · 1.54 KB
/
data_handler.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
import csv
from conf import configs
debug = configs['debug']
if type(debug) is not bool:
debug = False
def alipay_data(filepath):
data = []
with open(filepath, "r", encoding="gbk") as f:
reader = csv.reader(f)
is_start = False
jump_line = True
if debug:
print(reader)
for row in reader:
if not is_start:
# 支付宝可能存在空行,防止越界
for item in row:
if "电子客户回单" in item:
is_start = True
continue
# 跳过说明行
if jump_line:
jump_line = False
continue
data.append(row)
return data
# 微信导出字段:交易时间,交易类型,交易对方,商品,金额(元),支付方式,当前状态,备注
def wechat_data(filepath):
data = []
with open(filepath, "r", encoding="utf-8") as f:
# 使用 csv.reader 来处理带引号和逗号的复杂字段
reader = csv.reader(f)
is_start = False
jump_line = True
if debug:
print(reader)
for row in reader:
print(row)
if not is_start:
# 与支付宝统一格式
for item in row:
if "微信支付账单明细列表" in item:
is_start = True
continue
if jump_line:
jump_line = False
continue
data.append(row)
return data