Handle token method for saving token token to a file
This commit is contained in:
parent
dcc5cb1cb6
commit
deb19d78ae
3 changed files with 29 additions and 15 deletions
17
testing.py
17
testing.py
|
|
@ -26,16 +26,7 @@ API = APIClient(
|
|||
# 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=2)
|
||||
API.handle_token() # This will load the token from file if it exists and is valid, or sign in to get a new one if not.
|
||||
|
||||
'''
|
||||
END IMPORTANT BIT
|
||||
|
|
@ -50,8 +41,8 @@ def save_response(response):
|
|||
|
||||
|
||||
# print("-----------Get a user profile----------------")
|
||||
# profile = API.run_job('userprofile.get', "simon-little")
|
||||
# print(profile)
|
||||
profile = API.run_job('userprofile.get', "simon-little")
|
||||
print(profile)
|
||||
# print("-------------- Get a branch -----------------")
|
||||
# branch = API.run_job('branch.get', "music")
|
||||
# print(branch)
|
||||
|
|
@ -138,7 +129,7 @@ def save_response(response):
|
|||
# x += 1
|
||||
|
||||
# save_response(API.run_job('notification.listnotifications'))
|
||||
save_response(API.run_job('notification.markallasread'))
|
||||
# save_response(API.run_job('notification.markallasread'))
|
||||
|
||||
# save_response(API.run_job('feed.cafefeed'))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue