Spaces:
Runtime error
Runtime error
from datetime import timedelta | |
from enum import Enum | |
from typing import Any, Optional | |
from hibiapi.utils.cache import cache_config | |
from hibiapi.utils.config import APIConfig | |
from hibiapi.utils.decorators import enum_auto_doc | |
from hibiapi.utils.net import catch_network_error | |
from hibiapi.utils.routing import BaseEndpoint, dont_route | |
Config = APIConfig("wallpaper") | |
class WallpaperCategoryType(str, Enum): | |
"""ๅฃ็บธๅ็ฑป""" | |
girl = "girl" | |
"""ๅฅณ็""" | |
animal = "animal" | |
"""ๅจ็ฉ""" | |
landscape = "landscape" | |
"""่ช็ถ""" | |
anime = "anime" | |
"""ไบๆฌกๅ """ | |
drawn = "drawn" | |
"""ๆ็ป""" | |
mechanics = "mechanics" | |
"""ๆบๆขฐ""" | |
boy = "boy" | |
"""็ท็""" | |
game = "game" | |
"""ๆธธๆ""" | |
text = "text" | |
"""ๆๅญ""" | |
CATEGORY: dict[WallpaperCategoryType, str] = { | |
WallpaperCategoryType.girl: "4e4d610cdf714d2966000000", | |
WallpaperCategoryType.animal: "4e4d610cdf714d2966000001", | |
WallpaperCategoryType.landscape: "4e4d610cdf714d2966000002", | |
WallpaperCategoryType.anime: "4e4d610cdf714d2966000003", | |
WallpaperCategoryType.drawn: "4e4d610cdf714d2966000004", | |
WallpaperCategoryType.mechanics: "4e4d610cdf714d2966000005", | |
WallpaperCategoryType.boy: "4e4d610cdf714d2966000006", | |
WallpaperCategoryType.game: "4e4d610cdf714d2966000007", | |
WallpaperCategoryType.text: "5109e04e48d5b9364ae9ac45", | |
} | |
class WallpaperOrderType(str, Enum): | |
"""ๅฃ็บธๆๅบๆนๅผ""" | |
hot = "hot" | |
"""็ญ้จ""" | |
new = "new" | |
"""ๆๆฐ""" | |
class WallpaperEndpoint(BaseEndpoint): | |
base = "http://service.aibizhi.adesk.com" | |
async def request( | |
self, endpoint: str, *, params: Optional[dict[str, Any]] = None | |
) -> dict[str, Any]: | |
response = await self.client.get( | |
self._join( | |
base=WallpaperEndpoint.base, | |
endpoint=endpoint, | |
params=params or {}, | |
) | |
) | |
return response.json() | |
# ๅฃ็บธๆ้ฒ็้พtoken, ไธๅปบ่ฎฎ้ฟๆถ้ด็ผๅญ | |
async def wallpaper( | |
self, | |
*, | |
category: WallpaperCategoryType, | |
limit: int = 20, | |
skip: int = 0, | |
adult: bool = True, | |
order: WallpaperOrderType = WallpaperOrderType.hot, | |
): | |
return await self.request( | |
"v1/wallpaper/category/{category}/wallpaper", | |
params={ | |
"limit": limit, | |
"skip": skip, | |
"adult": adult, | |
"order": order, | |
"first": 0, | |
"category": CATEGORY[category], | |
}, | |
) | |
# ๅฃ็บธๆ้ฒ็้พtoken, ไธๅปบ่ฎฎ้ฟๆถ้ด็ผๅญ | |
async def vertical( | |
self, | |
*, | |
category: WallpaperCategoryType, | |
limit: int = 20, | |
skip: int = 0, | |
adult: bool = True, | |
order: WallpaperOrderType = WallpaperOrderType.hot, | |
): | |
return await self.request( | |
"v1/vertical/category/{category}/vertical", | |
params={ | |
"limit": limit, | |
"skip": skip, | |
"adult": adult, | |
"order": order, | |
"first": 0, | |
"category": CATEGORY[category], | |
}, | |
) | |