From a4579d67fd4e8fa46d457e9e71b213230da942b1 Mon Sep 17 00:00:00 2001 From: zevav Date: Wed, 17 May 2017 14:08:57 -0400 Subject: [PATCH] added texts from twilio --- requirements.txt | 26 ++++++++++++++++++++++++++ splurgebot.py | 19 +++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2f9763e..c5f9f0c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,28 @@ +appnope==0.1.0 +asn1crypto==0.22.0 +cffi==1.10.0 +cryptography==1.8.1 +decorator==4.0.11 +idna==2.5 +ipython==6.0.0 +ipython-genutils==0.2.0 +jedi==0.10.2 +packaging==16.8 +pexpect==4.2.1 +pickleshare==0.7.4 plaid-python==2.0.1 +prompt-toolkit==1.0.14 +ptyprocess==0.5.1 +pycparser==2.17 +Pygments==2.2.0 +PyJWT==1.5.0 +pyOpenSSL==17.0.0 +pyparsing==2.2.0 +PySocks==1.6.7 +pytz==2017.2 requests==2.14.2 +simplegeneric==0.8.1 +six==1.10.0 +traitlets==4.3.2 +twilio==6.1.2 +wcwidth==0.1.7 diff --git a/splurgebot.py b/splurgebot.py index c79241d..4a68a6f 100644 --- a/splurgebot.py +++ b/splurgebot.py @@ -1,16 +1,21 @@ import datetime import os import time +from twilio.rest import Client as TwilioClient import plaid CHECK_FOR_NEW_TRANSACTIONS_EVERY_X_MINUTES = 5 ALERT_FOR_TRANSACTIONS_GTE = 500 +MY_CELL = os.getenv('MY_CELL') +MY_TWILIO_NUM = os.getenv('MY_TWILIO_NUM') -c = plaid.Client(client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.getenv('PLAID_SECRET'), - public_key=os.getenv('PLAID_PUBLIC_KEY'), environment='development') +plaid_client = plaid.Client(client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.getenv('PLAID_SECRET'), + public_key=os.getenv('PLAID_PUBLIC_KEY'), environment=os.getenv('PLAID_ENV')) +twilio_client = TwilioClient(os.getenv('TWILIO_SID'), os.getenv('TWILIO_TOKEN')) -ACCESS_ID = 'access id for a specific account and user from Plaid' +# this is an access ID from Plaid for a specific user and bank/credit account +PLAID_ACCESS_ID = os.getenv('PLAID_ACCESS_ID') transaction_ids = set() @@ -18,13 +23,14 @@ 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'] + for transaction in plaid_client.Transactions.get(PLAID_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"]}') + message = (f'hey, a transaction hit your account that exceeds ${ALERT_FOR_TRANSACTIONS_GTE}: ' + f'{transaction["date"]} {transaction["name"]} ${transaction["amount"]}') + twilio_client.api.account.messages.create(to=MY_CELL, from_=MY_TWILIO_NUM, body=message) def main(): @@ -33,6 +39,7 @@ def main(): transaction_ids.add(transaction['transaction_id']) if transaction['amount'] >= ALERT_FOR_TRANSACTIONS_GTE: alert(transaction) + break time.sleep(CHECK_FOR_NEW_TRANSACTIONS_EVERY_X_MINUTES * 60)