39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import http.server
|
|
from oauthlib.oauth2 import WebApplicationClient
|
|
import webbrowser
|
|
import urllib3
|
|
import re
|
|
import subprocess
|
|
import ast
|
|
|
|
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
CLIENT_ID = "a79bae348867427690ca6df9903e4af0"
|
|
CLIENT_SECRET = "VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5"
|
|
AUTH_URL = "https://oauth.battle.net/authorize"
|
|
REDIRECT_URI = 'http://localhost:5635/login_success'
|
|
|
|
token_file = open(".oauthtoken", "r")
|
|
oauth_token = token_file.readline()
|
|
|
|
|
|
command = ["curl", "-sH", "Authorization: Bearer {}".format(oauth_token), "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US"]
|
|
# | jq -r '[ .wow_accounts[0].characters[].level | select(.) ] | add / length'
|
|
# Run the command
|
|
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
|
|
# Get the output and error message (if any)
|
|
output = ast.literal_eval(result.stdout)
|
|
error = result.stderr
|
|
|
|
characters = output['wow_accounts'][0]['characters']
|
|
# Check if it was successful
|
|
if result.returncode == 0:
|
|
print("Success:")
|
|
for char in characters:
|
|
print(char['name'], char['level'])
|
|
else:
|
|
print("Error:")
|
|
print(error)
|