nongxin_parser.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import pandas as pd
  2. from tkinter import messagebox
  3. from flow_parser_base import FlowParserBase
  4. class NongxinFlowParser(FlowParserBase):
  5. """农信银行流水解析器"""
  6. def parse(self, flow_file_path):
  7. """解析农信银行流水文件,返回标准化的流水数据"""
  8. try:
  9. flow_df = pd.read_excel(flow_file_path, header=None)
  10. flow_data = []
  11. for idx, row in flow_df.iterrows():
  12. if idx < 3:
  13. continue
  14. if pd.isna(row[0]) or str(row[0]).strip() == '':
  15. continue
  16. try:
  17. date_part = str(row[0]).strip()
  18. time_part = str(row[1]).strip()
  19. transaction_time = f"{date_part} {time_part}"
  20. shouzhi_type = str(row[2]).strip()
  21. income_amount = pd.to_numeric(str(row[3]).replace(',', '') if not pd.isna(row[3]) else '0', errors='coerce')
  22. expense_amount = pd.to_numeric(str(row[4]).replace(',', '') if not pd.isna(row[4]) else '0', errors='coerce')
  23. if pd.isna(income_amount):
  24. income_amount = 0
  25. if pd.isna(expense_amount):
  26. expense_amount = 0
  27. balance = str(row[5]).strip() if not pd.isna(row[5]) else ''
  28. opponent_name = str(row[6]).strip() if not pd.isna(row[6]) else ''
  29. opponent_bank = str(row[8]).strip() if not pd.isna(row[8]) else ''
  30. summary = str(row[9]).strip() if not pd.isna(row[9]) else ''
  31. if income_amount > 0 or expense_amount > 0:
  32. flow_data.append({
  33. "交易时间": transaction_time,
  34. "对方户名": opponent_name,
  35. "摘要": summary,
  36. "收入": income_amount,
  37. "支出": expense_amount,
  38. "余额": balance
  39. })
  40. except Exception as e:
  41. continue
  42. if not flow_data:
  43. messagebox.showerror("错误", "农信银行流水解析失败:未找到有效数据")
  44. return None
  45. standard_flow = pd.DataFrame(flow_data)
  46. return standard_flow
  47. except Exception as e:
  48. messagebox.showerror("错误", f"解析农信银行流水失败:{str(e)}")
  49. return None
  50. def get_bank_name(self):
  51. """返回银行名称"""
  52. return "农信银行"