-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaffix_servant.py
130 lines (113 loc) · 4.54 KB
/
affix_servant.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from pathlib import Path
from rio import pull
from bnet import BnetBroker
AFFIX_ROTATION = [
[9, 124, 6],
[10, 134, 7],
[9, 136, 123],
[10, 135, 6],
[9, 3, 8],
[10, 124, 11],
[9, 135, 7],
[10, 136, 8],
[9, 134, 11],
[10, 3, 123],
]
class AffixServant:
"""
Provides the current affixes.
This week affixes are pulled from raider.io.
Next week affixes are only available if a valid bnet token is provided.
"""
def __init__(self, proxy=''):
self.proxy = proxy
self.next_week_affixes_available = False
self._bnet_broker = BnetBroker()
rio_current_affixes_url = 'https://raider.io/api/v1/mythic-plus/affixes?region=eu&locale=en'
responses = pull([rio_current_affixes_url], self.proxy)
bnet_response = {}
if self._bnet_broker.is_operational():
bnet_all_affixes_url = f'/data/wow/keystone-affix/index'
bnet_response = self._bnet_broker.pull(bnet_all_affixes_url, 'static-eu')
else:
print("WARNING: bnet_broker not operational! Affix display will be incomplete.")
self.current_affixes = []
if len(responses) >= 0 and responses[0].ok:
r = responses[0].json()
self.current_affixes = r['affix_details']
else:
self.current_affixes = [{
"id": 0,
"name": "No_Response",
"description": "can't get any information from Raider.io",
"wowhead_url": "",
"icon": "inv_misc_volatilewater"
}]
self._fix_current_affixes()
self.all_affixes = {}
if bnet_response:
r = bnet_response
for affix in r['affixes']:
self.all_affixes[affix['id']] = affix['name']
self.next_week_affixes_available = True
def get_affixes(self):
affixes = {
'this_week': self.get_this_week_affixes(),
'next_week': self.get_next_week_affixes(),
'tyrannical': self.is_tyrannical_week()
}
return affixes
def get_this_week_affixes(self):
return self.current_affixes
def get_next_week_affixes(self):
if not self.next_week_affixes_available:
return None
next_week_affixes = []
next_week_affix_ids = self.search_next_affix_week()
if next_week_affix_ids:
for affix_id in next_week_affix_ids:
affix = {}
if affix_id == -1:
unknown_affix = {
'id': -1,
'name': "???",
'description': ""
}
affix = unknown_affix
else:
affix['id'] = affix_id
affix['name'] = self.all_affixes[affix_id]
affix['description'] = "" # TODO: You can get this here: /data/wow/keystone-affix/{keystoneAffixId}
affix['icon'] = self.get_affix_icon_name(affix_id)
affix['wowhead_url'] = f'https://wowhead.com/affix={affix_id}'
next_week_affixes.append(affix)
return next_week_affixes
return None
def search_next_affix_week(self):
current_affix_ids = [affix['id'] for affix in self.current_affixes]
for i, possible_affix_week in enumerate(AFFIX_ROTATION):
if possible_affix_week == current_affix_ids:
return AFFIX_ROTATION[(i+1) % len(AFFIX_ROTATION)]
return None
def get_affix_icon_name(self, affix_id):
if not self._bnet_broker.is_operational():
return ""
affix_media_url = f'/data/wow/media/keystone-affix/{affix_id}'
response = self._bnet_broker.pull(affix_media_url, 'static-eu')
if response:
for asset in response['assets']:
if asset['key'] == 'icon':
icon_url = asset['value']
# NOTE: this is maybe a little bit hacky
p = Path(icon_url)
return p.stem
return ""
def is_tyrannical_week(self):
affixes = self.get_this_week_affixes()
return affixes[0]['id'] == 9
def _fix_current_affixes(self):
# Note: fix the affix icons for the raider.io pulled affixes.
# e.g. they use a different icon for thundering than the official source (bnet)
if self._bnet_broker.is_operational():
for a in self.current_affixes:
a['icon'] = self.get_affix_icon_name(a['id'])