renames and testing using fx to explore output

This commit is contained in:
tonydero 2025-01-07 14:29:26 -07:00
parent 8521e5a271
commit da134e3d6b
8 changed files with 86 additions and 48 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.oauthtoken
*.csv

4
account-json.sh Normal file
View File

@ -0,0 +1,4 @@
token="$(cat .oauthtoken)"
curl -H "Authorization: Bearer $token" "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US" > ./output/account.json
# output_json=$(curl -H "Authorization: Bearer $token" "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US")
#jq -r '.wow_accounts[0].characters[] | [.name, .level] | @csv'

View File

@ -1,38 +0,0 @@
import http.server
from oauthlib.oauth2 import WebApplicationClient
import webbrowser
import re
import subprocess
import ast
token_file = open(".oauthtoken", "r")
oauth_token = token_file.readline()
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)
# Get the output and error message (if any)
output = result.stdout
output_dict = ast.literal_eval(output)
error = result.stderr
characters = output_dict['wow_accounts'][0]['characters']
char_dicts = []
# 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)
else:
print("Error:")
print(error)

1
output/account.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,3 @@
CLIENT_ID="a79bae348867427690ca6df9903e4af0"
CLIENT_SECRET="VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5"
# CLIENT_ACCESS_TOKEN_RESPONSE="$(curl -u $CLIENT_ID:$CLIENT_SECRET -d grant_type=client_credentials https://oauth.battle.net/token)"
# CLIENT_ACCESS_TOKEN=$(echo $CLIENT_ACCESS_TOKEN_RESPONSE | jq -r '.access_token')
OAUTH_ACCESS_CODE="USGUSBUZGNQ29JBWKMVFWHIUKIUXUHWW88"
OAUTH_ACCESS_TOKEN_RESPONSE="$(curl -X POST https://oauth.battle.net/token -u $CLIENT_ID:$CLIENT_SECRET -d http://localhost:5635/login_success -d grant_type=authorization_code -d code=$OAUTH_ACCESS_CODE)"
# OAUTH_ACCESS_TOKEN=$(echo $OAUTH_ACCESS_TOKEN_RESPONSE | jq -r '.access_token')
echo $OAUTH_ACCESS_TOKEN_RESPONSE
# curl -H "Authorization: Bearer $CLIENT_ACCESS_TOKEN" "https://us.api.blizzard.com/data/wow/token/?namespace=dynamic-us" | jq
token=$(cat .oauthtoken)
curl -H "Authorization: Bearer $token" "https://us.api.blizzard.com/data/wow/token/?namespace=dynamic-us" | fx
# curl -H "Authorization: Bearer $CLIENT_ACCESS_TOKEN" "https://us.api.blizzard.com/data/wow/guild/proudmoore/stellar/roster?namespace=profile-us" | jq '.members[].character.name'

78
toon-info.py Normal file
View File

@ -0,0 +1,78 @@
import http.server
from oauthlib.oauth2 import WebApplicationClient
import webbrowser
import re
import subprocess
import ast
import json
import csv
from datetime import datetime
token_file = open(".oauthtoken", "r")
oauth_token = token_file.readline()
def json_print(dict_in):
print(json.dumps(dict_in, indent=2))
def oauth_api_curl(url):
command = ["curl", "-sH", "Authorization: Bearer {}".format(
oauth_token), url]
result = subprocess.run(command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True)
if result.returncode == 0:
return result.stdout
else:
error = result.stderr
print("Error:")
return error
account_str = oauth_api_curl("https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US")
account_eval = ast.literal_eval(account_str)
if type(account_eval) == dict:
characters = account_eval['wow_accounts'][0]['characters']
char_dicts = []
for char in characters:
char_dict = {
'id': char['id'],
'name': char['name'],
'level': char['level'],
'faction': char['faction']['name'],
'race': char['playable_race']['name'],
'class': char['playable_class']['name'],
'realm': char['realm']['name'],
}
char_dicts.append(char_dict)
char_keys = char_dicts[0].keys()
with open('./output/toons-{}.csv'.format(datetime.now().strftime("%Y%m%d-%H%M%S")), 'w', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, char_keys)
dict_writer.writeheader()
dict_writer.writerows(char_dicts)
prot_char_url = char['protected_character']['href']
prot_char_str = oauth_api_curl(prot_char_url)
prot_char_eval = ast.literal_eval(prot_char_str)
if type(prot_char_eval) == dict:
print(prot_char_eval['protected_stats'].keys())
else:
print('eval\'d type:', type(prot_char_eval))
profs_url = "https://us.api.blizzard.com/profile/wow/character/{}/{}/professions?namespace=profile-us&locale=en_US".format(
char['realm']['slug'], char['name'].lower())
profs_str = oauth_api_curl(profs_url)
profs_eval = ast.literal_eval(profs_str)
if type(profs_eval) == dict:
json_print(profs_eval)
else:
print('eval\'d type:', type(profs_eval))
else:
print('eval\'d type:', type(account_eval))

View File

@ -1 +0,0 @@
curl -H "Authorization: Bearer USCdfWcbxv1hGYQDPWSXbvr84SHme9eJ5T" "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US" | jq -r '.wow_accounts[0].characters[] | [.name, .level] | @csv'