From 1bf37280223c2c0eff4a7abbe5361b85e787e317 Mon Sep 17 00:00:00 2001 From: julius Date: Fri, 1 Nov 2024 11:02:01 +0100 Subject: [PATCH] Initial commit --- main.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 32 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/main.py b/main.py new file mode 100644 index 0000000..c4e680b --- /dev/null +++ b/main.py @@ -0,0 +1,58 @@ +import uvicorn +from datetime import datetime +from fastapi import FastAPI, Request +from fastapi.middleware.cors import CORSMiddleware +from pydantic import BaseModel + +app = FastAPI(title="Team Prefs", root_path="/team") +origins = [ + "*", + "http://localhost", + "http://localhost:3000", + "https://localhost", + "https://0124816.xyz", + "http://0124816.xyz:3001", +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + + +class Submission(BaseModel): + person: str + players: list[str] + + +db_file = "team.db" + + +@app.get("/players/") +def get_players() -> list[str]: + players = [line.strip() for line in open("players", "r")] + return players + + +@app.post("/submit/") +def submit(sub: Submission, request: Request): + print(datetime.now().strftime("%Y%m%d-%H%M%S"), sub.person, sub.players) + with open(db_file, "a") as f: + f.write( + "\t".join( + [ + request.client.host, + datetime.now().strftime("%Y%m%d-%H%M%S"), + sub.person, + ",".join(sub.players), + ] + ) + ) + f.write("\n") + + +if __name__ == "__main__": + uvicorn.run("main:app", workers=1, port=8096) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5df5a6d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,32 @@ +annotated-types==0.7.0 +anyio==4.6.2.post1 +click==8.1.7 +contourpy==1.3.0 +cycler==0.12.1 +fastapi==0.115.4 +fonttools==4.54.1 +h11==0.14.0 +idna==3.10 +joblib==1.4.2 +kiwisolver==1.4.7 +matplotlib==3.9.2 +numpy==2.1.2 +packaging==24.1 +pillow==11.0.0 +pydantic==2.9.2 +pydantic-core==2.23.4 +pygraphviz==1.14 +pyparsing==3.2.0 +pyqt6==6.7.1 +pyqt6-qt6==6.7.3 +pyqt6-sip==13.8.0 +python-dateutil==2.9.0.post0 +scikit-learn==1.5.2 +scipy==1.14.1 +six==1.16.0 +sniffio==1.3.1 +starlette==0.41.2 +tenacity==9.0.0 +threadpoolctl==3.5.0 +typing-extensions==4.12.2 +uvicorn==0.32.0