DengFengLai's picture
DF.
0a1b571
raw
history blame
3.38 kB
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")
@enum_auto_doc
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",
}
@enum_auto_doc
class WallpaperOrderType(str, Enum):
"""ๅฃ็บธๆŽ’ๅบๆ–นๅผ"""
hot = "hot"
"""็ƒญ้—จ"""
new = "new"
"""ๆœ€ๆ–ฐ"""
class WallpaperEndpoint(BaseEndpoint):
base = "http://service.aibizhi.adesk.com"
@dont_route
@catch_network_error
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, ไธๅปบ่ฎฎ้•ฟๆ—ถ้—ด็ผ“ๅญ˜
@cache_config(ttl=timedelta(hours=2))
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, ไธๅปบ่ฎฎ้•ฟๆ—ถ้—ด็ผ“ๅญ˜
@cache_config(ttl=timedelta(hours=2))
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],
},
)