-
-
Save duplaja/4df7e47230566894b7ee2a7e45ac2f50 to your computer and use it in GitHub Desktop.
SimpleFIN Print Transactions (to terminal)
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
import datetime | |
import time | |
import requests | |
import base64 | |
import pickle | |
def setup_function(file_name): | |
setup_token = input('SimpleFin Setup Token? ') | |
claim_url = base64.b64decode(setup_token) | |
response = requests.post(claim_url) | |
access_url = response.text | |
data = {"access_url":access_url} | |
with open(file_name,"wb") as file: | |
pickle.dump(data, file) | |
file.close() | |
return None | |
def main(): | |
file_name = "simplefin-data.pickle" | |
try: | |
with open(file_name,"rb") as file: | |
data = pickle.load(file) | |
access_url = data["access_url"] | |
file.close() | |
except IOError: | |
access_url = '' | |
if not access_url: | |
setup_function(file_name) | |
with open(file_name,"rb") as file: | |
data = pickle.load(file) | |
access_url = data["access_url"] | |
file.close() | |
scheme, rest = access_url.split('//', 1) | |
auth, rest = rest.split('@', 1) | |
url = scheme + '//' + rest + '/accounts' | |
username, password = auth.split(':', 1) | |
start_datetime = datetime.date(2024, 2, 15) | |
start_unixtime = int(round(time.mktime(start_datetime.timetuple()))) | |
end_datetime = datetime.date(2024, 2, 25) | |
end_unixtime = int(round(time.mktime(end_datetime.timetuple()))) | |
response = requests.get(url, auth=(username, password),params={'start-date': start_unixtime, 'end-date': end_unixtime, 'pending': 1}) | |
data = response.json() | |
accounts = data['accounts'] | |
for account in accounts: | |
name = '\n'+account['org']['name']+' - '+account['name']+'\n\n' | |
print(name) | |
transactions = account['transactions'] | |
for transaction in transactions: | |
print(transaction) | |
print('--------------------------------------------------') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Edit the dates in line 55 and 57 as desired. On line 60, change pending to 0 to exclude pending transactions.