-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpaypal2qbo.py
43 lines (35 loc) · 1.35 KB
/
paypal2qbo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import csv
import argparse
import time
def main():
parser = argparse.ArgumentParser()
parser.add_argument('infile', nargs='+', type=argparse.FileType('r'))
args = parser.parse_args()
transactions = []
for f in args.infile:
for line in csv.DictReader(f):
# The single line has a gross payment and a fee payment, so we need to split those apart
tstamp = time.strptime('{Date} { Time}'.format(**line), '%m/%d/%Y %H:%M:%S')
# This is the "gross" payment
transactions.append((
tstamp,
'{ Type} From { Name}'.format(**line),
line[' Gross'].replace(',', '')
))
if line[' Fee'] != '0.00':
transactions.append((
tstamp,
'{ Type} Fee From { Name}'.format(**line),
line[' Fee'].replace(',', '')
))
with open('QuickBooksOutput.csv', 'w') as f:
writer = csv.DictWriter(f, fieldnames=['Date', 'Description', 'Amount'])
writer.writeheader()
for txn in sorted(transactions, key=lambda l: time.mktime(l[0])):
writer.writerow({
'Date': time.strftime('%m/%d/%Y', txn[0]),
'Description': txn[1],
'Amount': txn[2]
})
if __name__ == '__main__':
main()