qnloft-spider/理财记账/zs_bank.py

45 lines
1.2 KiB
Python

'''
招商银行账单
'''
from datetime import datetime
import pandas as pd
def reset_date(date):
# 获取当前日期和时间
current_datetime = datetime.now()
# 从当前日期中提取年份
current_year = current_datetime.year
# 将整数转换为字符串并添加前导零,确保它至少有四位数
date_str = str(current_year) + str(date).zfill(4)
# 将输入字符串解析为日期对象
input_date = datetime.strptime(date_str, '%Y%m%d')
# 将日期对象格式化为所需的日期字符串格式
return input_date.strftime('%Y-%m-%d')
def pay_source(details):
res = ""
source = details.split('-')[0]
if source == '京东支付':
res = '京东'
elif source == '财付通':
res = '微信'
elif source == '支付宝':
res = '支付宝'
return res
class ZsBank:
def __init__(self, bill_file, sheet_name):
self.df = pd.read_excel(bill_file, sheet_name=sheet_name)
def get_zs_bank_bill(self):
self.df['金额'] = self.df['金额'].astype(str).str.replace(',', '', regex=True).astype(float)
total_sum = self.df['金额'].sum()
print(total_sum)
self.df['日期'] = self.df['日期'].apply(reset_date)
self.df['来源'] = self.df['详情'].apply(pay_source)
return self.df