33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import pymysql, json
|
|
cfg = json.load(open('db_config.json'))
|
|
conn = pymysql.connect(host=cfg['host'], port=cfg['port'], user=cfg['user'],
|
|
password=cfg.get('password'), database=cfg['database'], charset='utf8mb4')
|
|
cur = conn.cursor()
|
|
cur.execute("""SELECT note FROM variable_expenses
|
|
WHERE member_id=3 AND note LIKE '%[微信]%' AND recorded_date BETWEEN '2026-01-01' AND '2026-06-30'""")
|
|
notes = [r[0] for r in cur.fetchall()]
|
|
# 分析 note 格式种类
|
|
import collections
|
|
fmt = collections.Counter()
|
|
for n in notes:
|
|
if n.startswith('[微信] 支出'):
|
|
fmt['导入格式-支出'] += 1
|
|
elif '微信' in n and '转账' in n:
|
|
fmt['含微信+转账'] += 1
|
|
else:
|
|
fmt['其他:' + n[:30]] += 1
|
|
print("note格式分布:")
|
|
for k, v in fmt.most_common(10):
|
|
print(f" {v}笔 {k}")
|
|
# 看几条历史微信的note样例
|
|
print("\n样例(非本次导入格式):")
|
|
shown = 0
|
|
for n in notes:
|
|
if not n.startswith('[微信] 支出'):
|
|
print(" ", n[:60])
|
|
shown += 1
|
|
if shown >= 5: break
|
|
conn.close()
|