-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
54 lines (38 loc) · 1.31 KB
/
api.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
50
51
52
53
from os import environ
import configcatclient as configcat
from nordigen import NordigenClient
cc_key = environ["CONFIGCAT_KEY"]
cc_client = configcat.create_client(cc_key)
print("ConfigCat is set up")
def get_money() -> str:
"""
Gets money from Nordigen API
:raises Exception: If the API call fails
:return: Account balance
"""
secret_id = cc_client.get_value('secret_id', None)
secret_key = cc_client.get_value('secret_key', None)
requisition_id = cc_client.get_value('requisition_id', None)
print("Got configs")
client = NordigenClient(
secret_id=secret_id,
secret_key=secret_key
)
token_data = client.generate_token()
client.exchange_token(token_data["refresh"])
accounts = client.requisition.get_requisition_by_id(
requisition_id=requisition_id
)
account_id = accounts["accounts"][0]
account = client.account_api(id=account_id)
try:
balances = account.get_balances()["balances"]
except Exception as e:
print(f"Exception has occured: {e}")
raise
for balance in balances:
if balance["balanceType"] == "forwardAvailable":
b = balance["balanceAmount"]["amount"]
print(f"Got balance: {b}")
return b
raise Exception("Couldn't retrieve balance")