-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New web server for managing credentials and linking bank accounts (#10)
* Check new web server into version control * Log user sync before pushing to database * Use `before_first_request` decorator to initialize db * Run Flask app in `__main__` * Rename `web-server` to `web_server` so it can be imported * Add files necessary for gcloud app engine deployment * Simplify module api to run new web server
- Loading branch information
Showing
27 changed files
with
860 additions
and
452 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,17 @@ | ||
import argparse | ||
import sys | ||
import os | ||
import threading | ||
import webbrowser | ||
from time import sleep | ||
|
||
from gsheets_plaid.data import (get_access_tokens, get_spreadsheet_id_from_file, | ||
load_creds_from_file) | ||
from gsheets_plaid.services import GOOGLE_SCOPES, generate_gsheets_service, generate_plaid_client | ||
from gsheets_plaid.sync import get_spreadsheet_url | ||
from dotenv import load_dotenv | ||
|
||
# Main parser | ||
description = 'Sync transaction data to Google Sheets using Plaid.' | ||
parser = argparse.ArgumentParser(description=description, prog='gsheets_plaid') | ||
parser.add_argument('-v', '--verbose', action='store_true', help='print verbose output') | ||
subparsers = parser.add_subparsers(dest='action', required=True, metavar='sub-command') | ||
from gsheets_plaid.web_server.main import run_web_server | ||
|
||
load_dotenv(os.path.join(os.path.dirname(__file__), 'web_server/.env')) | ||
t = threading.Thread(target=run_web_server, kwargs={'ssl_context': 'adhoc'}) | ||
t.start() | ||
sleep(1) # Wait for the server to start | ||
|
||
# Parser for the 'init' command | ||
parser_init = subparsers.add_parser('init', help='initialize') | ||
|
||
|
||
# Parser for the 'link' command | ||
parser_link = subparsers.add_parser('link', help='link new accounts, manage existing accounts') | ||
parser_link.add_argument( | ||
'--env', | ||
type=str, | ||
choices=['sandbox', 'development', 'production'], | ||
help='temporarily run with a different env type (does NOT change config)') | ||
|
||
|
||
# Parser for the 'sync' command | ||
parser_sync = subparsers.add_parser('sync', help='sync transactions from linked accounts') | ||
parser_sync.add_argument('--days', type=int, default=30, help='number of days to sync') | ||
parser_sync.add_argument( | ||
'--env', | ||
type=str, | ||
choices=['sandbox', 'development', 'production'], | ||
help='temporarily run with a different env type (does NOT change config)') | ||
|
||
if len(sys.argv) == 1: | ||
parser.print_help(sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
args = parser.parse_args() | ||
|
||
from gsheets_plaid.initialization import CONFIG, is_initialized | ||
|
||
if not is_initialized() and args.action != 'init': | ||
parser.error('Please run "gsheets_plaid init" before running any other commands.') | ||
|
||
if args.env: | ||
CONFIG['PLAID_ENV'] = args.env | ||
|
||
if args.action == 'init': | ||
from gsheets_plaid.initialization import initialize | ||
initialize() | ||
elif args.action == 'link': | ||
from gsheets_plaid.link import run_link_server | ||
run_link_server(CONFIG['PLAID_LINK_PORT']) | ||
elif args.action == 'sync': | ||
from gsheets_plaid.sync import sync_transactions | ||
plaid_env = CONFIG.get('PLAID_ENV') | ||
plaid_secret = CONFIG.get(f'PLAID_SECRET_{plaid_env.upper()}', None) | ||
if not plaid_secret: | ||
raise ValueError(f'Either {plaid_env} is incorrect or PLAID_SECRET_{plaid_env.upper()} does not exist!') | ||
gsheets_credentials = load_creds_from_file(GOOGLE_SCOPES) | ||
gsheets_service = generate_gsheets_service(gsheets_credentials) | ||
plaid_client = generate_plaid_client(plaid_env, CONFIG.get('PLAID_CLIENT_ID'), plaid_secret) | ||
access_tokens = get_access_tokens() | ||
spreadsheet_id = get_spreadsheet_id_from_file(gsheets_service, verbose=True) | ||
sync_transactions(gsheets_service, plaid_client, access_tokens, spreadsheet_id, args.days) | ||
webbrowser.open(get_spreadsheet_url(gsheets_service, spreadsheet_id), new=1, autoraise=True) | ||
# Direct the user to Plaid Link | ||
webbrowser.open('https://localhost:8080/', new=1, autoraise=True) | ||
t.join() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Oops, something went wrong.