-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
77 lines (51 loc) · 1.72 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
from typing import List, Optional
from enum import Enum
from fastapi import FastAPI, status, applications
from fastapi.openapi.docs import get_swagger_ui_html
from pydantic import BaseModel
from importilaj_funkcioj import importas_el_meetup, importas_el_duolingo
# Fiksu swagger_ui versio
def swagger_monkey_patch(*args, **kwargs):
return get_swagger_ui_html(
*args,
**kwargs,
swagger_js_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css"
)
applications.get_swagger_ui_html = swagger_monkey_patch
class ImportPeto(BaseModel):
URL: str
class Evento(BaseModel):
titolo: str
urbo: Optional[str]
ligilo: str
reta: bool
landa_id: str
latitudo: Optional[str]
longitudo: Optional[str]
adreso: str
horzono: str
komenco: str
fino: str
enhavo: str
priskribo: str
class Fonto(BaseModel):
nomo: str
priskribo: Optional[str] = None
fontoj = [{"nomo": "Meetup"}, {"nomo": "Duolingo"}]
class FontNomoj(str, Enum):
meetup = "meetup"
duolingo = "duolingo"
app = FastAPI()
@app.get("/")
async def root():
return {"mesaĝo": "Saluton SEPanoj!"}
@app.get("/fontoj", status_code=status.HTTP_200_OK, response_model=List[Fonto])
async def legu_fontojn():
return fontoj
@app.post("/meetup", status_code=status.HTTP_200_OK, response_model=Evento)
async def importu_el_meetup(importPeto: ImportPeto):
return importas_el_meetup(importPeto.URL)
@app.post("/duolingo", status_code=status.HTTP_200_OK, response_model=Evento)
async def importu_el_duolingo(importPeto: ImportPeto):
return importas_el_duolingo(importPeto.URL)