#!/usr/bin/env python3 # -*- coding: utf-8 -*- """查询汪礼平与汪和平相关的全部转账/红包/收支记录""" import json, pymysql 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() # 支出方向(微信转出给汪和平) print('=== 汪礼平 → 汪和平(支出/转出) ===') cur.execute(""" SELECT recorded_date, amount, note FROM variable_expenses WHERE member_id=1 AND note LIKE '%汪和平%' ORDER BY recorded_date """) for d, a, n in cur.fetchall(): print(f' {d} ¥{float(a):>9.2f} {"支出" if "支出" in n else "转出"} {n}') # 收入方向(汪和平转入→汪礼平) print() print('=== 汪和平 → 汪礼平(收入/转入) ===') cur.execute(""" SELECT recorded_date, amount, source, note FROM income_records WHERE member_id=1 AND (source LIKE '%汪和平%' OR note LIKE '%汪和平%') ORDER BY recorded_date """) rows = cur.fetchall() if rows: for d, a, s, n in rows: print(f' {d} ¥{float(a):>9.2f} {"收入" if "收入" in n else "转入"} 来源:{s} {n}') else: # income_records 可能没有汪和平相关,检查所有收入 cur.execute("SELECT recorded_date, amount, source, note FROM income_records WHERE member_id=1 ORDER BY recorded_date") print(' (income_records 中未匹配,全部收入记录如下:)') for d, a, s, n in cur.fetchall(): print(f' {d} ¥{float(a):>9.2f} 来源:{s} {n or ""}') conn.close()