Initial commit

This commit is contained in:
julius 2024-11-01 11:02:01 +01:00
commit 1bf3728022
Signed by: julius
GPG Key ID: C80A63E6A5FD7092
2 changed files with 90 additions and 0 deletions

58
main.py Normal file
View File

@ -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)

32
requirements.txt Normal file
View File

@ -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