-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadptars.py
More file actions
71 lines (53 loc) · 1.62 KB
/
adptars.py
File metadata and controls
71 lines (53 loc) · 1.62 KB
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
from pydantic import ValidationError
from pydantic import BaseModel
from typing import List, Optional
from http_client import HTTP_Client
from pprint import pprint
class DailyQuote(BaseModel):
author: str
quote: str
source: str
class Recipe(BaseModel):
content: str
keyword: List[str]
source: str
title: str
class Event(BaseModel):
description: str
time: str
class Calendar(BaseModel):
title: str
events: List[Event]
class Inspiration(BaseModel):
content: str
keyword: List[str]
source: str
title: str
class DataModel(BaseModel):
daily_quote: Optional[DailyQuote] = None
recipe: Optional[Recipe] = None
calendar: Optional[Calendar] = None
inspiration: Optional[Inspiration] = None
class Face(BaseModel):
x: int
y: int
w: int
h: int
class FaceDetectionResult(BaseModel):
face_count: int
faces: List[Face]
if __name__ == "__main__":
try:
http_client = HTTP_Client()
json_data = http_client.get()
pprint(json_data)
data = DataModel(**json_data)
print(data.daily_quote.author if data.daily_quote else "No Quote")
print(data.recipe.title if data.recipe else "No Recipe")
print(data.recipe.content if data.recipe else "No Recipe Content")
print(data.calendar.title if data.calendar else "No Calendar")
for event in data.calendar.events if data.calendar else []:
print(f"- {event.description} at {event.time}")
print(data.inspiration.content if data.inspiration else "No Inspiration")
except ValidationError as e:
print("data valid error:", e)