renamed get_some_transactions modules
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
from pprint import pprint
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# twilio.rest has a Client too, so let's avoid a namespace collision
|
# twilio.rest has a Client too, so let's avoid a namespace collision
|
||||||
@@ -11,12 +12,13 @@ plaid_client = PlaidClient(client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.get
|
|||||||
|
|
||||||
# https://plaid.com/docs/api/#transactions
|
# https://plaid.com/docs/api/#transactions
|
||||||
MAX_TRANSACTIONS_PER_PAGE = 500
|
MAX_TRANSACTIONS_PER_PAGE = 500
|
||||||
OMIT_CATEGORIES = ["Transfer", "Credit Card", "Deposit"]
|
OMIT_CATEGORIES = ["Transfer", "Credit Card", "Deposit", "Payment"]
|
||||||
|
OMIT_ACCOUNT_SUBTYPES = ['cd', 'savings']
|
||||||
|
|
||||||
|
|
||||||
def get_some_transactions(access_token: str, start_date: str, end_date: str) -> List[dict]:
|
def get_some_transactions(access_token: str, start_date: str, end_date: str) -> List[dict]:
|
||||||
account_ids = [account['account_id'] for account in plaid_client.Accounts.get(access_token)['accounts']
|
account_ids = [account['account_id'] for account in plaid_client.Accounts.get(access_token)['accounts']
|
||||||
if account['subtype'] not in ['cd', 'savings']]
|
if account['subtype'] not in OMIT_ACCOUNT_SUBTYPES]
|
||||||
|
|
||||||
num_available_transactions = plaid_client.Transactions.get(access_token, start_date, end_date,
|
num_available_transactions = plaid_client.Transactions.get(access_token, start_date, end_date,
|
||||||
account_ids=account_ids)['total_transactions']
|
account_ids=account_ids)['total_transactions']
|
||||||
@@ -34,3 +36,8 @@ def get_some_transactions(access_token: str, start_date: str, end_date: str) ->
|
|||||||
for category in transaction['category'])]
|
for category in transaction['category'])]
|
||||||
|
|
||||||
return transactions
|
return transactions
|
||||||
|
|
||||||
|
some_transactions = get_some_transactions(os.getenv('CHASE_ACCESS_TOKEN'), '1972-01-01', '2017-05-26')
|
||||||
|
print(f"there are {len(some_transactions)} transactions")
|
||||||
|
pprint([transaction for transaction in some_transactions if transaction['amount'] < 0])
|
||||||
|
|
||||||
23
get_some_transactions_simple.py
Normal file
23
get_some_transactions_simple.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import os
|
||||||
|
from pprint import pprint
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
# twilio.rest has a Client too, so let's avoid a namespace collision
|
||||||
|
from plaid import Client as PlaidClient
|
||||||
|
|
||||||
|
plaid_client = PlaidClient(client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.getenv('PLAID_SECRET'),
|
||||||
|
public_key=os.getenv('PLAID_PUBLIC_KEY'), environment=os.getenv('PLAID_ENV'))
|
||||||
|
|
||||||
|
|
||||||
|
def get_some_transactions(access_token: str, start_date: str, end_date: str) -> List[dict]:
|
||||||
|
return plaid_client.Transactions.get(access_token, start_date, end_date)
|
||||||
|
|
||||||
|
some_transactions = get_some_transactions(os.getenv('CHASE_ACCESS_TOKEN'), '1972-01-01', '2017-05-26')
|
||||||
|
|
||||||
|
print(f'there are {some_transactions["total_transactions"]} total transactions between those dates.')
|
||||||
|
print(f'get_some_transactions returned {len(some_transactions["transactions"])} transactions.')
|
||||||
|
pprint(some_transactions['transactions'][0].keys())
|
||||||
|
print({category
|
||||||
|
for transaction in some_transactions['transactions'] if transaction['category'] is not None
|
||||||
|
for category in transaction['category']})
|
||||||
|
pprint(some_transactions['accounts'])
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import os
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
# twilio.rest has a Client too, so let's avoid a namespace collision
|
|
||||||
from plaid import Client as PlaidClient
|
|
||||||
|
|
||||||
plaid_client = PlaidClient(client_id=os.getenv('PLAID_CLIENT_ID'), secret=os.getenv('PLAID_SECRET'),
|
|
||||||
public_key=os.getenv('PLAID_PUBLIC_KEY'), environment=os.getenv('PLAID_ENV'))
|
|
||||||
|
|
||||||
|
|
||||||
def get_some_transactions(access_token: str, start_date: str, end_date: str) -> List[dict]:
|
|
||||||
return plaid_client.Transactions.get(access_token, start_date, end_date)
|
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
click==6.7
|
certifi==2017.4.17
|
||||||
flake8==3.3.0
|
chardet==3.0.3
|
||||||
Jinja2==2.9.6
|
idna==2.5
|
||||||
MarkupSafe==1.0
|
plaid-python==2.0.2
|
||||||
mccabe==0.6.1
|
|
||||||
plaid==0.1.7
|
|
||||||
pycodestyle==2.3.1
|
|
||||||
pyflakes==1.5.0
|
|
||||||
PyJWT==1.5.0
|
PyJWT==1.5.0
|
||||||
PySocks==1.6.7
|
PySocks==1.6.7
|
||||||
pytz==2017.2
|
pytz==2017.2
|
||||||
PyYAML==3.12
|
requests==2.17.3
|
||||||
requests==2.14.2
|
|
||||||
six==1.10.0
|
six==1.10.0
|
||||||
twilio==6.3.0
|
twilio==6.3.0
|
||||||
|
urllib3==1.21.1
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ from typing import List
|
|||||||
|
|
||||||
from twilio.rest import Client as TwilioClient
|
from twilio.rest import Client as TwilioClient
|
||||||
|
|
||||||
|
from get_yesterdays import get_yesterdays_transactions
|
||||||
|
|
||||||
twilio_client = TwilioClient(os.getenv('TWILIO_SID'), os.getenv('TWILIO_TOKEN'))
|
twilio_client = TwilioClient(os.getenv('TWILIO_SID'), os.getenv('TWILIO_TOKEN'))
|
||||||
|
|
||||||
|
|
||||||
@@ -13,4 +15,4 @@ def send_summary(transactions: List[dict]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
send_summary(get_yesterdays())
|
send_summary(get_yesterdays_transactions())
|
||||||
|
|||||||
Reference in New Issue
Block a user