-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
46 lines (43 loc) · 1.29 KB
/
client.py
File metadata and controls
46 lines (43 loc) · 1.29 KB
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
import plaid
class plaid_client:
def __init__(self, pid, psecret, ppubkey, penv='development', papiv='2019-05-29'):
self.pid = pid
self.psecret = psecret
self.ppubkey = ppubkey
self.penv = penv
self.papiv = papiv
self.c = None
def connect(self):
if self.c is not None:
print('client already connected')
return
self.c = plaid.Client(
client_id = self.pid,
secret=self.psecret,
public_key=self.ppubkey,
environment=self.penv,
api_version=self.papiv
)
def get_balance(self, key):
'''
key is a tuple of key name, api key
'''
if self.c is None:
self.connect()
print('+ ', key[0], '...')
try:
bal = self.c.Accounts.balance.get(key[1])
except plaid.errors.InstitutionError as e:
bal = None
print("OH NO!!!!!! Couldn't get a balance for some reason")
print(e)
pass
except plaid.errors.PlaidError as e:
raise Exception(e)
err = None
if bal:
if bal['item']:
err = bal['item']['error']
if err is not None:
raise Exception(err)
return bal