Skip to content

Instantly share code, notes, and snippets.

@duplaja
Last active May 2, 2024 18:20
Show Gist options
  • Save duplaja/4df7e47230566894b7ee2a7e45ac2f50 to your computer and use it in GitHub Desktop.
Save duplaja/4df7e47230566894b7ee2a7e45ac2f50 to your computer and use it in GitHub Desktop.
SimpleFIN Print Transactions (to terminal)
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()
@duplaja
Copy link
Author

duplaja commented Feb 19, 2024

Edit the dates in line 55 and 57 as desired. On line 60, change pending to 0 to exclude pending transactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment