Last active
December 24, 2022 16:54
-
-
Save dangarbri/9e993373aba85e7107b7a224426fb158 to your computer and use it in GitHub Desktop.
Continuously integrate transactions from American Express into the EveryDollar budgeting app.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Uses selenium based APIs for American Express and Everydollar | |
continuously import transactions into everydollar. | |
Since everydollar doesn't natively support linking an American Express account | |
""" | |
from amex_selenium import AmexAPI | |
from everydollar_api import EveryDollarAPI | |
from time import sleep | |
from datetime import datetime, timedelta | |
import pickle | |
import os | |
# Create your own creds.py with these variables | |
from creds import amex_username, amex_password, everydollar_username, everydollar_password | |
DATE_THRESHOLD = datetime.fromisoformat("2022-12-20 00:00:00") | |
TRANSACTIONS_FILE = "transactions.pickle" | |
captured_transactions = [] # Watch for when pending transactions clear | |
merchant_prefix = "Amex " | |
def save_transactions(): | |
with open(TRANSACTIONS_FILE, "wb") as fp: | |
pickle.dump(captured_transactions, fp) | |
def load_transactions(): | |
if os.path.exists(TRANSACTIONS_FILE): | |
with open(TRANSACTIONS_FILE, "rb") as fp: | |
global captured_transactions | |
captured_transactions = pickle.load(fp) | |
def apply_prefix(merchant): | |
return "Amex " + merchant | |
if __name__ == "__main__": | |
load_transactions() | |
# Get webdrivers | |
everydollar = EveryDollarAPI() | |
amex = AmexAPI() | |
# Log in to each site | |
everydollar.login(everydollar_username, everydollar_password) | |
amex.login(amex_username, amex_password) | |
# Get transactions from amex | |
transactions = amex.get_recent_transactions() | |
for new_transaction in transactions: | |
if (new_transaction.date > DATE_THRESHOLD) and (new_transaction not in captured_transactions): | |
print(f"Adding transaction {new_transaction}") | |
everydollar.add_transaction(new_transaction.date, apply_prefix(new_transaction.merchant), new_transaction.amount) | |
captured_transactions.append(new_transaction) | |
save_transactions() | |
sleep(1) | |
# Close browsers/logout TODO: Add proper logout button | |
amex.close() | |
everydollar.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone [email protected]:Appsolutely-Wonderful/amex-selenium-api.git | |
git clone [email protected]:Appsolutely-Wonderful/everydollar-selenium-api.git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Imports are from:
amex_selenium: https://github.com/Appsolutely-Wonderful/amex-selenium-api
everydollar_api: https://github.com/Appsolutely-Wonderful/everydollar-selenium-api