main.py 729 B

12345678910111213141516171819202122232425262728293031323334
  1. from typing import Optional
  2. from fastapi import FastAPI
  3. from pydantic import BaseModel
  4. from fastapi.staticfiles import StaticFiles
  5. app = FastAPI()
  6. app.mount("/static", StaticFiles(directory="static"), name="static")
  7. class Item(BaseModel):
  8. name: str
  9. price: float
  10. is_offer: Optional[bool] = None
  11. @app.get("/")
  12. def read_root():
  13. return {"Hello": "World"}
  14. @app.get("/items/{item_id}")
  15. def read_item(item_id: int, q: Optional[str] = None):
  16. return {"item_id": item_id, "q": q}
  17. @app.post("/enter_invite_code")
  18. def update_item(item_id: int, item: Item):
  19. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
  20. return {"item_name": item.name, "item_id": item_id}