diff --git a/example.py b/example.py index e832d6e..fc10cb8 100644 --- a/example.py +++ b/example.py @@ -1,16 +1,42 @@ from blizzardapi2 import BlizzardApi +import requests +import webbrowser -api_client = BlizzardApi("a79bae348867427690ca6df9903e4af0", "8l1KhVr1DkcqpXQl454WZmtlN3LvgBO5") +CLIENTID = "a79bae348867427690ca6df9903e4af0" +CLIENTSECRET = "VfFc4JRxn4MpA5zRVut1gPIh6E5WrEC5" +OAUTH_TOKEN = "USCdfWcbxv1hGYQDPWSXbvr84SHme9eJ5T" +REGION = "us" +LOCALE = "en_US" + +api_client = BlizzardApi(CLIENTID, CLIENTSECRET) + + +# def create_access_token(client_id, client_secret, region = 'us'): +# data = { 'grant_type': 'client_credentials' } +# response = requests.post('https://%s.battle.net/oauth/token' % region, data=data, auth=(client_id, client_secret)) +# return response.json() +# +# response = create_access_token(CLIENTID, CLIENTSECRET) +# print(response) # Unprotected API endpoint -categories_index = api_client.wow.game_data.get_achievement_categories_index("us", "en_US") +# categories_index = api_client.wow.game_data.get_achievement_categories_index("us", "en_US") +# print(categories_index) # Protected API endpoint -# summary = api_client.wow.profile.get_account_profile_summary("us", "en_US", "access_token") +# summary = api_client.wow.profile.get_account_profile_summary(REGION, LOCALE, OAUTH_TOKEN) +# print(summary) # Wow Classic endpoint -connected_realms_index = api_client.wow.game_data.get_connected_realms_index("us", "en_US", is_classic=True) +# connected_realms_index = api_client.wow.game_data.get_connected_realms_index("us", "en_US", is_classic=True) +# print(connected_realms_index) -print(categories_index) -# print(summary) -print(connected_realms_index) +# def get_character_profile(realm, character): +# profile_info = api_client.wow.profile.get_character_profile_summary(REGION, LOCALE, realm, character) +# return profile_info +# +# character_faction = get_character_profile("area-52", "izyrra")["faction"]["name"] +# +# print(character_faction) + +webbrowser.register('floorp').open_new_tab("https://bbc.co.uk") diff --git a/oauth-test.py b/oauth-test.py new file mode 100644 index 0000000..883e2b7 --- /dev/null +++ b/oauth-test.py @@ -0,0 +1,28 @@ +import requests +from http.server import * +import urllib.parse +import webbrowser + +CLIENTID = "a79bae348867427690ca6df9903e4af0" +AUTH_URL = "https://oauth.battle.net/authorize" + +# replace with your own http handlers +def wait_for_request(server_class=HTTPServer, + handler_class=BaseHTTPRequestHandler): + server_address = ('', 5635) + httpd = server_class(server_address, handler_class) + return httpd.handle_request() + +def authenticate(): + scope = "openid" + redirect_uri = 'http://localhost:5635/login_success' + params = {'client_id': CLIENTID, 'scope': scope, 'response_type': 'code', + 'state': "AbCdEfG", 'redirect_uri': redirect_uri} + url = "{}?{}".format(AUTH_URL, urllib.parse.urlencode(params)) + webbrowser.open(url) + response = wait_for_request() + print(response) + +authenticate() + +# webbrowser.open_new_tab("https://oauth.battle.net/authorize?response_type=code&scope=openid&state=AbCdEfG&redirect_uri=http://localhost&client_id=" + CLIENTID) diff --git a/roster b/roster new file mode 100644 index 0000000..e69de29 diff --git a/testing.sh b/testing.sh new file mode 100644 index 0000000..6d8eb6d --- /dev/null +++ b/testing.sh @@ -0,0 +1,9 @@ +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_TOKEN_RESPONSE="$(curl -X POST https://oauth.battle.net/token -u $CLIENT_ID:$CLIENT_SECRET -d http://localhost -d grant_type=authorization_code -d code=$CLIENT_ACCESS_TOKEN)" +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 +# 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' diff --git a/token b/token new file mode 100644 index 0000000..e69de29 diff --git a/toons-avglvl.sh b/toons-avglvl.sh new file mode 100644 index 0000000..024eb97 --- /dev/null +++ b/toons-avglvl.sh @@ -0,0 +1 @@ +curl -sH "Authorization: Bearer USCdfWcbxv1hGYQDPWSXbvr84SHme9eJ5T" "https://us.api.blizzard.com/profile/user/wow?namespace=profile-us&locale=en_US" | jq -r '[ .wow_accounts[0].characters[].level | select(.) ] | add / length' diff --git a/toons-csv.sh b/toons-csv.sh new file mode 100644 index 0000000..f616a89 --- /dev/null +++ b/toons-csv.sh @@ -0,0 +1 @@ +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'