-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (27 loc) · 824 Bytes
/
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
from datetime import datetime
from fastapi import FastAPI
from fastapi.responses import FileResponse
from openpyxl import Workbook
app = FastAPI()
async def create_excel() -> str:
wb = Workbook()
ws = wb.active
ws["A1"] = "Hello World"
file_path = "hello_world.xlsx"
wb.save(file_path)
return file_path
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/excel")
async def get_excel():
file_path = await create_excel()
return FileResponse(
file_path,
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
@app.post("/receive_entity")
async def receive_entity(entity: dict):
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(f"entity_{date}.txt", "w") as f:
f.write(str(entity))