From 5b8695a5a9cbef905d24df2d056820a19d62a6a1 Mon Sep 17 00:00:00 2001 From: zevav Date: Wed, 17 May 2017 13:36:40 -0400 Subject: [PATCH] moved everything into one module, got Plaid piece working --- __init__.py | 8 -------- get_institution_info.py | 21 --------------------- splurgebot.py | 42 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 30 deletions(-) delete mode 100644 __init__.py delete mode 100644 get_institution_info.py diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 33accd8..0000000 --- a/__init__.py +++ /dev/null @@ -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') diff --git a/get_institution_info.py b/get_institution_info.py deleted file mode 100644 index 24e2570..0000000 --- a/get_institution_info.py +++ /dev/null @@ -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'] diff --git a/splurgebot.py b/splurgebot.py index 348b96b..c79241d 100644 --- a/splurgebot.py +++ b/splurgebot.py @@ -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()