Beispiel #1
0
def tool_bank():
    user = g.user

    client = Client(client_id='test_id', secret='test_secret')
    connect = client.connect(account_type='wells', username='******', password='******', email='*****@*****.**')

    if connect.ok:
        step = client.step(account_type='wells', mfa='tomato')

        if step.ok:
            data = json.loads(step.content)
            transactions = data['transactions']

            spent = {
                'school': 0,
                'essentials': 0,
                'snacks': 0,
                'gas': 0,
                'clothing': 0,
                'recreation': 0
            }
            for t in transactions:
                if t['type']['primary'] in ['place', 'digital']:
                    name = t['name'].lower()
                    amount = t['amount']
                    category = analyze_name(name)
                    spent[category] += amount
            pie = '['
            for cat, val in spent.iteritems():
                pie += '["%s",%d],' % (cat, val)
            pie = pie[:-1]
            pie += ']'
            return render_template('tool/bank.html', pie=pie)

    return render_template_string('Error')
Beispiel #2
0
class Plaid:

    def __init__(self, clientId, clientSecret, accessToken=None):
        self.client = Client(client_id=clientId, secret=clientSecret, access_token=accessToken)

    def connect(self, accountType, username, password, email):
        connect = self.client.connect(account_type=accountType, username=username, password=password, email=email)
        if connect.ok:
            json_response = json.loads(connect.content)
            return json_response;

    def answerMFA(self, accountType, mfaAnswer):
        step = self.client.step(account_type=accountType, mfa=mfaAnswer)
        if step.ok:
            transactions = json.loads(step.content)
            return transactions

    def getTransactions(self, options=None):
        transactions = self.client.transactions(options)
        if transactions.ok:
            transactions = json.loads(transactions.content)
            return transactions

    def delete(self):
        self.client.delete_user()
def test_step_requires_access_token():
    client = Client('myclientid', 'mysecret')
    with pytest.raises(Exception):
        client.step('bofa', 'foo')
def test_step():
    with patch('requests.post') as mock_requests_post:
        client = Client('myclientid', 'mysecret', 'token')
        client.step('bofa', 'foo')
        assert mock_requests_post.called
    def login_step(self, access_token, answer, account_type):
        client = Client(client_id=self.client_id, secret=self.secret)
        client.set_access_token(access_token)
        step = client.step(account_type=account_type, mfa=answer)

        return json.loads(step.content)