Skip to content

Instantly share code, notes, and snippets.

@chroming
Created October 3, 2017 11:09
Show Gist options
  • Save chroming/b00997bf0fee73345582023b61a04dda to your computer and use it in GitHub Desktop.
Save chroming/b00997bf0fee73345582023b61a04dda to your computer and use it in GitHub Desktop.
支付宝账单转MoneyWiz
# -*- coding:utf-8 -*-
import csv
csv_file = "~/1.csv"
new_file = "~/2.csv"
row_one = ["账户","转账","描述","交易对象","分类","日期","时间","金额","支票号码"]
def get_data(reader):
return list(reader)[5:-7]
def is_minus(row):
if '支出' in row[10]:
return '-'
elif '收入' in row[10]:
return '+'
elif '信用卡还款' in row[8]:
return '-'
elif '余额宝-单次转入' in row[8]:
return '+'
elif '余额宝-自动转入':
return None
elif '交易关闭' in row[11]:
return None
elif '资金转移' in row[15]:
return None
def ali_to_wiz(row):
return ["支付宝", "", row[8].rstrip(' '), row[7].rstrip(' '), "", *row[2].rstrip(' ').split(' '), is_minus(row) + row[9].rstrip(' '), row[0].rstrip(' \t')]
with open(csv_file, encoding='gbk') as ali:
reader = csv.reader(ali)
with open(new_file, mode='w', encoding='utf-8') as wiz:
writer = csv.writer(wiz)
writer.writerow(row_one)
for row in get_data(reader):
if is_minus(row):
new_row = ali_to_wiz(row)
print(new_row)
writer.writerow(new_row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment