Spaces:
Sleeping
Sleeping
Abhinav
commited on
feat: Map role icons to roles
Browse files- utils/models.py +24 -0
- utils/wolvesville.py +12 -1
utils/models.py
CHANGED
@@ -15,7 +15,13 @@ class Role(BaseModel):
|
|
15 |
name: str
|
16 |
description: str
|
17 |
image: Image
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def _getRoleObjects(roles: List[Dict[str, Union[str, Dict]]]):
|
21 |
roleList = []
|
@@ -48,3 +54,21 @@ def _getEmojiObjects(emojis: List[Dict[str, Union[str, Dict]]]):
|
|
48 |
print(e)
|
49 |
print(emoji)
|
50 |
return emojiList
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
name: str
|
16 |
description: str
|
17 |
image: Image
|
18 |
+
icons: List[str] = None
|
19 |
|
20 |
+
class RoleIcon(BaseModel):
|
21 |
+
id: str
|
22 |
+
rarity: str
|
23 |
+
image: Image
|
24 |
+
roleId: str
|
25 |
|
26 |
def _getRoleObjects(roles: List[Dict[str, Union[str, Dict]]]):
|
27 |
roleList = []
|
|
|
54 |
print(e)
|
55 |
print(emoji)
|
56 |
return emojiList
|
57 |
+
|
58 |
+
def _getRoleIconObjects(icons: List[Dict[str, Union[str, Dict]]]):
|
59 |
+
roleIconList = []
|
60 |
+
for icon in icons:
|
61 |
+
try:
|
62 |
+
entry = RoleIcon(**icon)
|
63 |
+
roleIconList.append(entry)
|
64 |
+
except Exception as e:
|
65 |
+
print(e)
|
66 |
+
print(icon)
|
67 |
+
return roleIconList
|
68 |
+
|
69 |
+
def _mapRoleRoleIcons(roles, icons):
|
70 |
+
for role in roles:
|
71 |
+
id = role.id
|
72 |
+
iconList = [icon.image.url for icon in icons if icon.roleId == id]
|
73 |
+
role.icons = iconList
|
74 |
+
return roles
|
utils/wolvesville.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from utils.models import _getRoleObjects, _getEmojiObjects
|
2 |
from dotenv import load_dotenv
|
3 |
from os import getenv
|
4 |
import requests
|
@@ -20,7 +20,18 @@ class Wolvesville:
|
|
20 |
roles = data["roles"]
|
21 |
resp = _getRoleObjects(roles=roles)
|
22 |
return resp
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def getEmojis(self):
|
25 |
emojis = requests.get(f"{self.url}/items/emojis", headers=self.headers).json()
|
26 |
resp = _getEmojiObjects(emojis=emojis)
|
|
|
1 |
+
from utils.models import _getRoleObjects, _getEmojiObjects, _getRoleIconObjects, _mapRoleRoleIcons
|
2 |
from dotenv import load_dotenv
|
3 |
from os import getenv
|
4 |
import requests
|
|
|
20 |
roles = data["roles"]
|
21 |
resp = _getRoleObjects(roles=roles)
|
22 |
return resp
|
23 |
+
|
24 |
+
def getRoleIcons(self):
|
25 |
+
data = requests.get(f"{self.url}/items/roleIcons", headers=self.headers).json()
|
26 |
+
resp = _getRoleIconObjects(icons=data)
|
27 |
+
return resp
|
28 |
|
29 |
+
def getRoleRoleIcons(self):
|
30 |
+
roles = self.getRoles()
|
31 |
+
icons = self.getRoleIcons()
|
32 |
+
mapping = _mapRoleRoleIcons(roles=roles, icons=icons)
|
33 |
+
return mapping
|
34 |
+
|
35 |
def getEmojis(self):
|
36 |
emojis = requests.get(f"{self.url}/items/emojis", headers=self.headers).json()
|
37 |
resp = _getEmojiObjects(emojis=emojis)
|