initial list of dicts for later csv saving

This commit is contained in:
tonydero 2024-12-25 22:57:41 -07:00
parent 6521b5ccb4
commit 8521e5a271
2 changed files with 20 additions and 16 deletions

View File

@ -1,38 +1,38 @@
import http.server import http.server
from oauthlib.oauth2 import WebApplicationClient from oauthlib.oauth2 import WebApplicationClient
import webbrowser import webbrowser
import urllib3
import re import re
import subprocess import subprocess
import ast 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") token_file = open(".oauthtoken", "r")
oauth_token = token_file.readline() 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"] 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) result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Get the output and error message (if any) # Get the output and error message (if any)
output = ast.literal_eval(result.stdout) output = result.stdout
output_dict = ast.literal_eval(output)
error = result.stderr error = result.stderr
characters = output['wow_accounts'][0]['characters'] characters = output_dict['wow_accounts'][0]['characters']
char_dicts = []
# Check if it was successful # Check if it was successful
if result.returncode == 0: if result.returncode == 0:
print("Success:") print("Success:")
for char in characters: for char in characters:
print(char['name'], char['level']) # 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: else:
print("Error:") print("Error:")
print(error) print(error)

View File

@ -1,9 +1,13 @@
import http.server import http.server
from oauthlib.oauth2 import WebApplicationClient from oauthlib.oauth2 import WebApplicationClient
import webbrowser import webbrowser
import urllib3
import re import re
import requests import requests
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
CLIENT_ID = "a79bae348867427690ca6df9903e4af0" CLIENT_ID = "a79bae348867427690ca6df9903e4af0"
CLIENT_SECRET = "VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5" CLIENT_SECRET = "VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5"
AUTH_URL = "https://oauth.battle.net/authorize" AUTH_URL = "https://oauth.battle.net/authorize"