File size: 3,382 Bytes
0a1b571
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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],
            },
        )