Working example

This commit is contained in:
simonwt 2026-03-30 21:37:02 +01:00
parent 3b8e1e558b
commit 070148cabe
3 changed files with 75 additions and 10 deletions

View file

@ -1,16 +1,33 @@
"""
Demonstrate basic usage
"""
from apiclient import APIClient
import jobs
import os
import os, simplejson as json
# Handle environment variables
from dotenv import load_dotenv
load_dotenv()
# Initialize API client with credentials from environment variables
API = APIClient(
client_id=os.getenv("client_id"),
client_secret=os.getenv("client_secret"),
debug=True
)
API.sign_in()
# profile = requests.userprofile
profile = jobs.userprofile.get(API, "simon-little")
# Keep a token cache to avoid unnecessary sign-ins during development.
# (In production, you'd handle this more robustly and securely)
if os.path.exists("token_data.json"):
with open("token_data.json", "r") as f:
token_data = json.load(f)
API.set_token(token_data)
# Get a new one if we don't have one or if the existing one is expired
if not API.is_token_valid():
tokendata = API.sign_in()
with open("token_data.json", "w") as f:
json.dump(tokendata, f, indent=4)
profile = API.run_job('userprofile.get', "simon-little")
print(profile)