StockAnalysis / services /avatar.py
igardner's picture
feat: transform to game platform - remove room codes, add test mode DURRRR bots, heavy logging, user notes
a0d9624
Raw History Blame Contribute Delete
976 Bytes
from config import Config
import random
class AvatarService:
@staticmethod
def get_styles():
return Config.AVATAR_STYLES_CC0
@staticmethod
def get_backgrounds():
return Config.AVATAR_BACKGROUNDS
@staticmethod
def build_url(style=None, seed=None, bg=None, format="svg"):
styles = AvatarService.get_styles()
style = style if style in styles else random.choice(styles)
if not seed:
seed = str(random.randint(100000, 999999))
base = f"https://api.dicebear.com/7.x/{style}/{format}"
url = f"{base}?seed={seed}"
if bg and bg != "transparent":
url += f"&backgroundColor={bg}"
return url
@staticmethod
def random_avatar():
return AvatarService.build_url(
style=random.choice(AvatarService.get_styles()),
seed=str(random.randint(100000, 999999)),
bg=random.choice(AvatarService.get_backgrounds()),
)