#!/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 amount, recorded_date, note FROM variable_expenses WHERE member_id=3 AND note LIKE '%[微信]%' AND recorded_date BETWEEN '2026-01-01' AND '2026-06-30' AND note NOT LIKE '[微信] 支出%' ORDER BY amount DESC""") print("=== 剩余历史[微信]记录(非本次导入) ===") tot = 0 for a, d, n in cur.fetchall(): print(f" ¥{float(a):>9.2f} {d} {n[:50]}") tot += float(a) print(f"小计: {tot:.2f}") conn.close()