moved everything into one module, got Plaid piece working
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
import plaid
|
|
||||||
|
|
||||||
|
|
||||||
plaid_client = plaid.Client(
|
|
||||||
client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.getenv('PLAID_SECRET'), public_key=os.getenv('PLAID_PUBLIC_KEY'),
|
|
||||||
environment='sandbox')
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
from __init__ import plaid_client
|
|
||||||
|
|
||||||
|
|
||||||
def get_banks_by_name(bank_name):
|
|
||||||
bank = plaid_client.Institutions.search(bank_name)
|
|
||||||
return bank['institutions']
|
|
||||||
|
|
||||||
|
|
||||||
def bank_can_get_transactions(bank):
|
|
||||||
return 'transactions' in bank['products']
|
|
||||||
|
|
||||||
#too_big_to_fail = ['Bank of America', 'Wells Fargo', 'Chase', 'Citi']
|
|
||||||
too_big_to_fail = ['Vermont Federal Credit Union', 'American Express', 'Citi']
|
|
||||||
# I only keep my money in banks that are too big to fail. If you can't beat 'em...
|
|
||||||
|
|
||||||
bank_dict = {}
|
|
||||||
|
|
||||||
for bank_name in too_big_to_fail:
|
|
||||||
banks = get_banks_by_name(bank_name)
|
|
||||||
if len(banks) > 0:
|
|
||||||
bank_dict[bank_name] = banks[0]['institution_id']
|
|
||||||
@@ -1 +1,41 @@
|
|||||||
from .get_institution_info import bank_dict
|
import datetime
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
import plaid
|
||||||
|
|
||||||
|
CHECK_FOR_NEW_TRANSACTIONS_EVERY_X_MINUTES = 5
|
||||||
|
ALERT_FOR_TRANSACTIONS_GTE = 500
|
||||||
|
|
||||||
|
c = plaid.Client(client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.getenv('PLAID_SECRET'),
|
||||||
|
public_key=os.getenv('PLAID_PUBLIC_KEY'), environment='development')
|
||||||
|
|
||||||
|
ACCESS_ID = 'access id for a specific account and user from Plaid'
|
||||||
|
|
||||||
|
transaction_ids = set()
|
||||||
|
|
||||||
|
|
||||||
|
def get_latest_transactions():
|
||||||
|
today = datetime.date.today().strftime('%Y-%m-%d')
|
||||||
|
return [transaction
|
||||||
|
for transaction in c.Transactions.get(ACCESS_ID, '1972-01-01', today)['transactions']
|
||||||
|
if transaction['transaction_id'] not in transaction_ids]
|
||||||
|
|
||||||
|
|
||||||
|
def alert(transaction):
|
||||||
|
print(f'hey, a transaction hit your account that exceeds ${ALERT_FOR_TRANSACTIONS_GTE}:')
|
||||||
|
print(f'{transaction["date"]} {transaction["name"]} ${transaction["amount"]}')
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
for transaction in get_latest_transactions():
|
||||||
|
transaction_ids.add(transaction['transaction_id'])
|
||||||
|
if transaction['amount'] >= ALERT_FOR_TRANSACTIONS_GTE:
|
||||||
|
alert(transaction)
|
||||||
|
|
||||||
|
time.sleep(CHECK_FOR_NEW_TRANSACTIONS_EVERY_X_MINUTES * 60)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user