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()), )