-
Notifications
You must be signed in to change notification settings - Fork 5
/
GetStatementOneYear.py
49 lines (39 loc) · 1.48 KB
/
GetStatementOneYear.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
44
45
46
47
48
49
import csv
from sbanken.Sbanken import Sbanken
from helpers.Helpers import getAccounts, getTransactionDate,getPayee,getMemo, getOut, getIn
def main():
# enable_debug_logging()
import api_settings
import pprint
sbanken = Sbanken(api_settings.CUSTOMERID, api_settings.CLIENTID, api_settings.SECRET)
accountNo = input('What is the account number:')
account = getAccounts(sbanken, accountNo)
if account == None:
print('Account not found!')
exit(1)
year = input('What year?')
if year == '':
year = 2020
year = int(year)
if year < 2000:
year = 2020
transactions = sbanken.GetTransactionsForYear(account['accountId'],year)
# pprint.pprint(transactions)
with open(account['name']+'_'+account['accountNumber']+'.csv', 'w', encoding='utf-8') as csvfile:
ktowriter = csv.writer(
csvfile,
delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
ktowriter.writerow(['Date', 'Payee', 'Memo', 'Outflow', 'Inflow'])
for item in transactions:
date = getTransactionDate(item)
payee = getPayee(item)
memo = getMemo(item)
outflow = getOut(item)
inflow = getIn(item)
ktowriter.writerow([date, payee, memo, outflow, inflow])
if payee.find('ircuit') > 0:
pprint.pprint(item)
print(date, payee, memo, outflow, inflow)
if __name__ == "__main__":
main()