generated from render-examples/fastapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (46 loc) · 1.4 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
from typing import Optional
from fastapi import FastAPI
import random # randomライブラリを追加
from fastapi.responses import HTMLResponse #インポート
app = FastAPI()
@app.get("/")
async def root():
return {"message": "soccer!!⚽"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
@app.get("/omikuji")
def omikuji():
omikuji_list = [
"大吉",
"中吉",
"小吉",
"吉",
"半吉",
"末吉",
"末小吉",
"凶",
"小凶",
"大凶"
]
return omikuji_list[random.randrange(10)]
@app.get("/index")
def index():
html_content = """
<html lang="ja">
<head>
<meta charset="UTF-8">
</head>
<body>
<h2 style="color: #ffffff; background-color: #00ff00;">好きな歌手</h2>
<p style="color: #ff0000">藤井風</p>
<h2 style="color: #ffffff; background-color: #00ff00;">はまっている曲</h2>
<p style="color: #ff0000">藤井風‐花</p>
<a href="https://www.google.co.jp/" title="検索">ググる</a>
</body>
</html>
"""
return HTMLResponse(content=html_content, status_code=200)
@app.post("/present")
async def new_naming(present):
return {"response": f"メッセージ {present}ありがとう。今日のあなたのラッキーカラーは赤色"}