-
Notifications
You must be signed in to change notification settings - Fork 6
/
event_helpers.py
58 lines (45 loc) · 1.67 KB
/
event_helpers.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
from game_constants import TROOP_RARITIES
def extract_name(raw_data):
if 'Name' in raw_data:
return {lang[:2]: name for lang, name in raw_data['Name'].items()}
return {}
def extract_lore(raw_data):
if 'Lore' in raw_data:
return {lang[:2]: lore for lang, lore in raw_data['Lore'].items()}
return {}
def roles_translation(roles):
return [f'[TROOP_ROLE_{role.upper()}]' for role in roles]
def extract_currencies(raw_data):
if 'CurrencyData' not in raw_data:
return []
return [
{
'icon': f'Liveeventscurrencies_{currency["Icon"]}_full',
'value': currency['Value'],
'name': {
lang[:2]: translation
for lang, translation in currency['Name'].items()
},
}
for currency in raw_data['CurrencyData']
]
def transform_battle(battle):
return {
'ids': battle.get('TeamRules', {}).get('TroopIds', []),
'names': {lang[:2]: translation for lang, translation in
battle['Name'].items()} if 'Name' in battle else {},
'icon': f'Liveevents/Liveeventslocationicons_{battle["Icon"]}_full.png' if 'Icon' in battle else '',
'rarity': TROOP_RARITIES[battle['Color']] if 'Color' in battle else '',
'raw_rarity': battle.get('Color'),
}
def get_first_battles(raw_data):
battles = []
for battle in raw_data.get('BattleArray', []):
if 'Name' not in battle:
continue
battles.append({
'name': battle['Name']['en_US'],
'rarity': TROOP_RARITIES[battle.get('Color', 0)],
'icon': battle.get('Icon', ''),
})
return battles