Python Excel微信数据转换 分析提取微信零钱数据
时间:2020-11-18 13:08:56
收藏:0
阅读:34
微信数据转换 分析提取微信零钱数据
# 微信数据转换
def wxProcessDo(total_list, begin, companyName, accountingTitle):
# 期初22.55 期末余额 421.65
total_list = total_list[17:]
# 倒序输出
total_list.reverse()
# 主体公司 会计科目
# companyName, accountingTitle = input("输入主体公司:"), input("输入会计科目:")
new_list = []
n = 0
new_list.append(
["序号", "交易ID", "支出金额", "存入金额", "账户余额", "承担主体", "对方开户行", "对方账号", "对方户名", "银行摘要", "凭证号", "凭证摘要", "凭证锁单状态",
"交易时间",
"主键", "交易日期", "主体公司", "会计科目", "期末数", "期初数"])
for i in range(len(total_list)):
if not (total_list[i][6] == "零钱" or total_list[i][7] == "已存入零钱" or total_list[i][7] == "提现已到账" or
total_list[i][
7] == "充值成功" or total_list[i][7] == "充值完成"):
continue
tradeDate = total_list[i][0].strftime(‘%Y-%m-%d‘)
tradeDateStr = total_list[i][0].strftime(‘%Y%m%d‘)
row_list = []
n = n + 1
row_list.append("=IF(O2<>O1,1,A1+1)") # 序号
row_list.append("") # 交易ID
# 支出金额
if total_list[i][4] == "支出" or total_list[i][7] == "提现已到账" or (
total_list[i][4] == "/" and total_list[i][7] == "支付成功"):
if total_list[i][10][:3] == ‘服务费‘:
fee = total_list[i][10][4:]
# 提现本金计入
row_list.append(total_list[i][5] - float(fee))
# 提现手续费计入
n = n + 1
row_list_fee = []
row_list_fee.append("=IF(O2<>O1,1,A1+1)") # 序号
row_list_fee.append("") # 交易ID
row_list_fee.append(float(fee)) # 支出金额
row_list_fee.append(0) # 存入金额
row_list_fee.append("") # 账户余额
row_list_fee.append("") # 承担主体
row_list_fee.append("") # 对方开户行
row_list_fee.append("零钱") # 对方账号
row_list_fee.append("") # 对方户名
row_list_fee.append("微信提现服务费")
row_list_fee.append("")
row_list_fee.append("")
row_list_fee.append("")
row_list_fee.append(total_list[i][0])
# 主键
row_list_fee.append("{}{}{}".format(companyName, tradeDateStr, accountingTitle))
row_list_fee.append(tradeDate) # 交易日期
row_list_fee.append(companyName) # 主体公司
row_list_fee.append(accountingTitle) # 会计科目
row_list_fee.append(begin) # 期末数
row_list_fee.append(begin) # 期初数
new_list.append(row_list_fee)
else:
row_list.append(total_list[i][5])
else:
row_list.append(0)
# 存入金额
if total_list[i][4] == "收入" or total_list[i][1] == "零钱充值":
row_list.append(total_list[i][5])
else:
row_list.append(0)
row_list.append("") # 账户余额
row_list.append("") # 承担主体
row_list.append("") # 对方开户行
row_list.append(total_list[i][6]) # 对方账号
row_list.append(total_list[i][2]) # 对方户名
row_list.append(
"{},{},{},{}".format(total_list[i][3], total_list[i][8], total_list[i][7], total_list[i][10])) # 银行摘要
row_list.append("") # 凭证号
row_list.append("") # 凭证摘要
row_list.append("") # 凭证锁单状态
row_list.append(total_list[i][0]) # 交易时间
# 主键
row_list.append("{}{}{}".format(companyName, tradeDateStr, accountingTitle))
row_list.append(tradeDate) # 交易日期
row_list.append(companyName) # 主体公司
row_list.append(accountingTitle) # 会计科目
row_list.append(begin) # 期末数
row_list.append(begin) # 期初数
new_list.append(row_list)
# 调整手续费行位置
if total_list[i][10][:3] == ‘服务费‘:
new_list[-1], new_list[-2] = new_list[-2], new_list[-1]
# 序号更正
for i in range(len(new_list)):
if i != 0:
if new_list[i][14] != new_list[i - 1][14]:
new_list[i][0] = 1
else:
new_list[i][0] = new_list[i - 1][0] + 1
return new_list
# 调整账户余额
def adjustBalance(total_list, begin=22.55):
for i in range(len(total_list)):
if i != 0:
begin = begin + total_list[i][3] - total_list[i][2]
if begin < 0.001:
begin = 0
total_list[i][4] = begin
return total_list
# 微信零钱明细整理
def wxTransform():
total_list = readFromExcel(file_path=".\\wx.xlsx")
print("成功读取{}条数据".format(len(total_list)))
print("--------微信零钱交易明细格式转换--------\n")
begin = float(input("请输入期初金额:"))
new_list = wxProcessDo(total_list, begin)
new_list = adjustBalance(new_list, begin)
writeToExcel(".\\wxok.xlsx", new_list)
评论(0)