-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast_api_run.py
45 lines (34 loc) · 1.46 KB
/
fast_api_run.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
from typing import Union
from fastapi import FastAPI, Query
from logger import logger
import json
app = FastAPI()
# Загрузка данных из config_default.json
with open("config_default.json", "r") as default_file:
config_default = json.load(default_file)
@app.get("/")
def read_root():
logger.debug("Received request on / endpoint")
return {"Hello": "World"}
@app.get("/titlegen")
async def generate_title(
the_text: str = Query(None, description="Text to be printed"),
background_colour: str = Query(None, description="Background color for printer"),
):
logger.debug("Received request on /titlegen endpoint")
# Создание копии config_default
config_query = config_default.copy()
# Обновление значений из запроса, если они переданы
if the_text:
config_query["printer"]["the_text"] = the_text
if background_colour:
config_query["printer"]["background_colour"] = background_colour
# Сохранение обновленной конфигурации в файл config_query.json
with open("config_query.json", "w") as query_file:
json.dump(config_query, query_file, indent=4)
logger.debug("Config file generated successfully")
return {"message": "Config file generated successfully"}
if __name__ == "__main__":
logger.debug('Fast api app started')
import uvicorn
uvicorn.run(app, port=8000, host="localhost")