From c76a92fe8299b40d976dd21f71730755686b8936 Mon Sep 17 00:00:00 2001 From: Brad Ganley Date: Sat, 27 Jul 2024 00:15:53 -0500 Subject: [PATCH] Spent way too much time figuring out why I'm too stupid to use dotenv --- reportguy.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/reportguy.py b/reportguy.py index 420aa8a..d703b41 100644 --- a/reportguy.py +++ b/reportguy.py @@ -1,4 +1,8 @@ import requests +from dotenv import load_dotenv +import os + +load_dotenv() def apiGetRequest(api_base, endpoint, params, headers): url = api_base + endpoint @@ -7,11 +11,15 @@ def apiGetRequest(api_base, endpoint, params, headers): if resp.status_code == 200: return resp.json() -api_base = 'https://portal.gotocompu.com/v4_6_release/apis/3.0' # Ctype on-prem api url +apiBase = os.environ["API_BASE"] +authToken = os.environ["AUTH_TOKEN"] +clientId = os.environ["CLIENT_ID"] endpoint = '/finance/agreementrecap' #endpoint for GET -headers = {'Authorization': '', 'clientId': ''} # DO NOT fill this out and then commit it to the publicly-viewable git repository, please +headers = {'Authorization': authToken, 'clientId': clientId} # DO NOT fill this out and then commit it to the publicly-viewable git repository, please params = {'pageSize': 50, 'conditions': 'agreementStatus!="CANCEL"', 'fields': 'id,companyName,name,lastInvoiceAmount,nextInvoiceAmount,agreementStatus'} # API call params--prepare to cry if your url encoding is sub-par -data = apiGetRequest(api_base, endpoint, params, headers) #Put it all together and whadya get + +data = apiGetRequest(apiBase, endpoint, params, headers) #Put it all together and whadya get + for item in data: #This is just iterating through whatever comes back and barfing the data in a readable way print(f"{item['companyName']} - {item['name']} \n - {item['agreementStatus']}")