wow-api-characterinfo/oauth-curlsp.py

39 lines
1.2 KiB
Python
Raw Normal View History

2024-12-25 16:33:19 -07:00
import http.server
from oauthlib.oauth2 import WebApplicationClient
import webbrowser
import re
import subprocess
import ast
2024-12-25 19:59:39 -07:00
token_file = open(".oauthtoken", "r")
oauth_token = token_file.readline()
2024-12-25 16:33:19 -07:00
def oauth_api_curl(url):
command = ["curl", "-sH", "Authorization: Bearer {}".format(oauth_token), "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US"]
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
2024-12-25 16:33:19 -07:00
# Get the output and error message (if any)
output = result.stdout
output_dict = ast.literal_eval(output)
2024-12-25 16:33:19 -07:00
error = result.stderr
characters = output_dict['wow_accounts'][0]['characters']
char_dicts = []
2024-12-25 16:33:19 -07:00
# Check if it was successful
if result.returncode == 0:
print("Success:")
for char in characters:
# TODO: API call for char['protected_character'] url via curl for more info
char_dict = {'id': char['id'],
'name': char['name'],
'level': char['level'],
'realm': char['realm']['name'],
'class': char['playable_class']['name']}
char_dicts.append(char_dict)
print(char_dict)
print(char)
2024-12-25 16:33:19 -07:00
else:
print("Error:")
print(error)