-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathschema.py
65 lines (48 loc) · 1.25 KB
/
schema.py
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
from datetime import datetime
from typing import Optional, Set, List
from pydantic import Field, HttpUrl, BaseModel, validator
class Url(BaseModel):
original: HttpUrl
large: HttpUrl
medium: HttpUrl
class Artwork(BaseModel):
title: str
id: int
class Author(BaseModel):
name: str
id: int
class Size(BaseModel):
width: int
height: int
class Setu(BaseModel):
artwork: Artwork
author: Author
sanity_level: int
r18: bool
page: int
create_date: datetime
size: Size
tags: List[str]
urls: Url
class Item(BaseModel):
r18: Optional[int] = Field(0, ge=0, le=2)
num: Optional[int] = Field(1, ge=1, le=50)
tags: Set[str] = set()
replace_url: Optional[HttpUrl] = None
class Config:
schema_extra = {
"example": {
"r18": "0",
"num": "1",
"tags": [],
"replace_url": "https://i.pixiv.re",
}
}
@validator('tags', pre=True)
def remove_empty_tags(cls, tags):
return {tag.strip() for tag in tags if tag.strip()}
class Setu_out(BaseModel):
detail: str = ''
count: int
tags: Set[str]
data: List[Setu]