Charts_4
Browse files
app.py
CHANGED
|
@@ -353,4 +353,64 @@ def privacy_policy():
|
|
| 353 |
<p>For privacy questions, contact us at mjproductions594@gmail.com</p>
|
| 354 |
</body>
|
| 355 |
</html>
|
| 356 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
<p>For privacy questions, contact us at mjproductions594@gmail.com</p>
|
| 354 |
</body>
|
| 355 |
</html>
|
| 356 |
+
"""
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
@app.post("/plaid/debug_data")
|
| 360 |
+
def plaid_debug_data(
|
| 361 |
+
request: ChatRequest,
|
| 362 |
+
credentials: HTTPAuthorizationCredentials = Depends(security),
|
| 363 |
+
):
|
| 364 |
+
user = verify_token(credentials.credentials)
|
| 365 |
+
if not user:
|
| 366 |
+
raise HTTPException(status_code=401, detail="Unauthorized")
|
| 367 |
+
|
| 368 |
+
access_token = request.access_token if request.access_token else SANDBOX_ACCESS_TOKEN
|
| 369 |
+
|
| 370 |
+
from plaid_client import plaid_client
|
| 371 |
+
from plaid.model.accounts_balance_get_request import AccountsBalanceGetRequest
|
| 372 |
+
from plaid.model.transactions_get_request import TransactionsGetRequest
|
| 373 |
+
from plaid.model.transactions_get_request_options import TransactionsGetRequestOptions
|
| 374 |
+
from datetime import date, timedelta
|
| 375 |
+
|
| 376 |
+
# Raw balances
|
| 377 |
+
bal_req = AccountsBalanceGetRequest(access_token=access_token)
|
| 378 |
+
bal_resp = plaid_client.accounts_balance_get(bal_req)
|
| 379 |
+
|
| 380 |
+
accounts_raw = []
|
| 381 |
+
for acc in bal_resp['accounts']:
|
| 382 |
+
accounts_raw.append({
|
| 383 |
+
"name": acc['name'],
|
| 384 |
+
"type": str(acc['type']),
|
| 385 |
+
"subtype": str(acc['subtype']),
|
| 386 |
+
"current": acc['balances']['current'],
|
| 387 |
+
"available": acc['balances']['available'],
|
| 388 |
+
"limit": acc['balances']['limit'],
|
| 389 |
+
})
|
| 390 |
+
|
| 391 |
+
# Raw transactions (last 10)
|
| 392 |
+
end_date = date.today()
|
| 393 |
+
start_date = end_date - timedelta(days=30)
|
| 394 |
+
txn_req = TransactionsGetRequest(
|
| 395 |
+
access_token=access_token,
|
| 396 |
+
start_date=start_date,
|
| 397 |
+
end_date=end_date,
|
| 398 |
+
options=TransactionsGetRequestOptions(count=20, include_personal_finance_category=True)
|
| 399 |
+
)
|
| 400 |
+
txn_resp = plaid_client.transactions_get(txn_req)
|
| 401 |
+
|
| 402 |
+
txns_raw = []
|
| 403 |
+
for txn in txn_resp['transactions'][:20]:
|
| 404 |
+
txns_raw.append({
|
| 405 |
+
"date": str(txn['date']),
|
| 406 |
+
"name": txn['name'],
|
| 407 |
+
"amount": txn['amount'],
|
| 408 |
+
"category": txn.get('personal_finance_category', {}).get('primary', 'UNKNOWN'),
|
| 409 |
+
"account_id": txn['account_id'],
|
| 410 |
+
})
|
| 411 |
+
|
| 412 |
+
return {
|
| 413 |
+
"accounts": accounts_raw,
|
| 414 |
+
"transactions": txns_raw,
|
| 415 |
+
"total_transactions": txn_resp['total_transactions'],
|
| 416 |
+
}
|