-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create auto_setup_fake_account.py not good API * new_test_user_data
- Loading branch information
1 parent
08a75cb
commit 26a3acd
Showing
10 changed files
with
3,115 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from API import Core, Data | ||
import os | ||
from dotenv import load_dotenv | ||
import json | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
|
||
load_dotenv() | ||
API_KEY = os.getenv("API_KEY") | ||
user_id = os.getenv("user_id") | ||
|
||
api_key = API_KEY | ||
core_instance = Core(api_key) | ||
data_instance = Data() | ||
|
||
access_token = core_instance.get_auth_token() | ||
|
||
transactions = data_instance.get_transactions(user_id, access_token) | ||
|
||
tran_data = json.loads(transactions) | ||
|
||
transaction_list = tran_data['data'] | ||
|
||
transactions = [] | ||
for transaction in transaction_list: | ||
transaction = { | ||
'type': transaction['type'], | ||
'id': transaction['id'], | ||
'status': transaction['status'], | ||
'description': transaction['description'], | ||
'amount': transaction['amount'], | ||
'account': transaction['account'], | ||
'balance': transaction['balance'], | ||
'direction': transaction['direction'], | ||
'class': transaction['class'], | ||
'institution': transaction['institution'], | ||
'postDate': transaction['postDate'], | ||
'subClass_title': transaction['subClass']['title'] if transaction.get('subClass') else None, | ||
'subClass_code': transaction['subClass']['code'] if transaction.get('subClass') else None | ||
} | ||
transactions.append(transaction) | ||
|
||
# Create a DataFrame from the extracted data | ||
transaction_df = pd.DataFrame(transactions) | ||
transaction_df.to_csv('user7.csv', index=False) | ||
|
||
transaction_df['postDate'] = pd.to_datetime(transaction_df['postDate']) | ||
transaction_df.sort_values(by='postDate', inplace=True) | ||
plt.figure(figsize=(10, 6)) | ||
plt.plot(transaction_df['postDate'], transaction_df['balance'], marker='o') | ||
plt.title('Balance vs. Time') | ||
plt.xlabel('Date') | ||
plt.ylabel('Balance') | ||
plt.show() |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os | ||
import requests | ||
from dotenv import load_dotenv | ||
import webbrowser | ||
|
||
load_dotenv() | ||
API_KEY = os.getenv("API_KEY") | ||
PHONE = os.getenv("PHONE") | ||
|
||
|
||
class Fake: | ||
def __init__(self, api_key): | ||
self.api_key = api_key | ||
|
||
def get_auth_token(self): | ||
url = "https://au-api.basiq.io/token" | ||
headers = { | ||
"accept": "application/json", | ||
"basiq-version": "3.0", | ||
"content-type": "application/x-www-form-urlencoded", | ||
"Authorization": "Basic " + self.api_key | ||
} | ||
|
||
response = requests.post(url, headers=headers) | ||
response_data = response.json() # Extract JSON content from the response | ||
|
||
auth_token = response_data["access_token"] # Get the access token from the JSON data | ||
return auth_token | ||
|
||
@staticmethod | ||
def create_fake_user(mobile, access_token): | ||
url = "https://au-api.basiq.io/users" | ||
|
||
payload = { | ||
"email": "[email protected]", | ||
"mobile": mobile, | ||
"firstName": "Wentworth", | ||
"lastName": "Smith" | ||
} | ||
headers = { | ||
"accept": "application/json", | ||
"content-type": "application/json", | ||
"authorization": "Bearer " f"{access_token}" | ||
} | ||
|
||
response = requests.post(url, json=payload, headers=headers) | ||
response_data = response.json() | ||
return response_data.get('id') | ||
|
||
@staticmethod | ||
def connect_fake_account(user_id, mobile, access_token): | ||
url = f"https://au-api.basiq.io/users/{user_id}/auth_link" | ||
|
||
payload = { | ||
"mobile": mobile | ||
} | ||
headers = { | ||
"accept": "application/json", | ||
"content-type": "application/json", | ||
"authorization": "Bearer " f"{access_token}" | ||
} | ||
|
||
response = requests.post(url, json=payload, headers=headers) | ||
response_data = response.json() | ||
return response_data.get('links').get('self') | ||
|
||
|
||
load_dotenv() | ||
API_KEY = os.getenv("API_KEY") | ||
MOBILE = os.getenv("MOBILE") | ||
api_key = API_KEY | ||
mobile = MOBILE | ||
fake_instance = Fake(api_key) | ||
|
||
access_token = fake_instance.get_auth_token() | ||
user_id = fake_instance.create_fake_user(mobile, access_token) | ||
link = fake_instance.connect_fake_account(user_id, mobile, access_token) | ||
webbrowser.open(link) | ||
|
||
# Highly recommend use dashboard directly |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# User Information | ||
|
||
| User | Details | | ||
| :--- | :----------------------------------------------------------- | | ||
| 1 | Happy path persona with steady income, mortgage, credit card and predictable expenses | | ||
| 2 | Persona with income, missing expenses, BNPL activity and balance going up over time | | ||
| 3 | Persona with balances ranging between stable and diminishing over time | | ||
| 4 | Standard | | ||
| 5 | Standard | | ||
| 6 | Standard | | ||
| 7 | HooliGov Bank (AU00004) | |
Oops, something went wrong.