added texts from twilio

This commit is contained in:
2017-05-17 14:08:57 -04:00
parent 5b8695a5a9
commit a4579d67fd
2 changed files with 39 additions and 6 deletions

View File

@@ -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

View File

@@ -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)