60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
import requests
|
|
import os
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
import logging
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(funcName)s %(message)s",
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
origins = [
|
|
"http://localhost",
|
|
"http://localhost:4173",
|
|
"http://localhost:5173",
|
|
"http://localhost:8000",
|
|
]
|
|
|
|
api_app = FastAPI(title="api app")
|
|
|
|
|
|
@api_app.get("/sheet")
|
|
async def sheet():
|
|
users = {}
|
|
with open("data.txt", "r") as filedata:
|
|
for line in filedata:
|
|
if line.startswith("Исполнитель, Код"):
|
|
continue
|
|
if line.startswith("Операция"):
|
|
continue
|
|
if line.startswith("СПЦФ"):
|
|
continue
|
|
|
|
chunk = line.strip().split("\t")
|
|
if len(chunk[0].split(" ")) > 3:
|
|
name = chunk[0].split(" ")
|
|
users[str(name[-1])] = {
|
|
"name": name[0:-1],
|
|
"calendar": chunk[1],
|
|
"hours": chunk[2],
|
|
"percent": chunk[3],
|
|
}
|
|
|
|
return {"status": "success", "data": users}
|
|
|
|
|
|
app = FastAPI(title="main app")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.mount("/api", api_app)
|
|
app.mount("/", StaticFiles(directory="front/dist", html=True), name="front")
|