-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealm.py
More file actions
32 lines (26 loc) · 842 Bytes
/
realm.py
File metadata and controls
32 lines (26 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
from exceptions import APIConnectionError
def get_realm_list(access_token, region, locale):
try:
response = requests.get(
f'https://{region}.api.blizzard.com/data/wow/realm/index?namespace=dynamic-{region}&locale={locale}&access_token={access_token}' # noqa
)
except requests.exceptions.ConnectionError as e:
raise APIConnectionError(e)
if response.status_code == 401:
e = "Invalid access token"
raise APIConnectionError(e)
realm_list = response.json()
try:
del realm_list['_links']
except KeyError:
pass
try:
for realm in realm_list['realms']:
try:
del realm['key']
except KeyError:
pass
except KeyError:
pass
return realm_list.get('realms')