diff --git a/client.py b/client.py index 7437da2..1866c2d 100644 --- a/client.py +++ b/client.py @@ -3,12 +3,15 @@ import time from rich.console import Console from websocket import create_connection -from learn_sql_model.models.hero import Hero +from learn_sql_model.config import get_config +from learn_sql_model.models.hero import Heros + +config = get_config() def connect(): - id = 1 - url = f"ws://localhost:5000/ws/{id}" + url = f"ws://{config.api_client.url.replace('https://', '')}/ws/heros" + # url = f"ws://localhost:5000/ws/heros" Console().log(f"connecting to: {url}") ws = create_connection(url) Console().log(f"connected to: {url}") @@ -23,7 +26,8 @@ def watch(ws): try: data.append(ws.recv()) if data[-1].startswith("{"): - Console().log(Hero.parse_raw(data[-1])) + # Console().log(data[-1]) + Console().log(Heros.parse_raw(data[-1])) else: Console().log(data[-1]) except Exception as e: diff --git a/client_sender.py b/client_sender.py index 7809f4c..21c07db 100644 --- a/client_sender.py +++ b/client_sender.py @@ -3,8 +3,10 @@ import time from rich.console import Console from websocket import create_connection -id = 1 -url = f"ws://localhost:5000/ws/{id}" +from learn_sql_model.config import get_config + +config = get_config() +url = f"ws://{config.api_client.url.replace('https://', '')}/ws/heros" Console().log(f"connecting to: {url}") ws = create_connection(url) diff --git a/learn_sql_model/api/app.py b/learn_sql_model/api/app.py index 5d82280..7e3b5a8 100644 --- a/learn_sql_model/api/app.py +++ b/learn_sql_model/api/app.py @@ -1,25 +1,38 @@ from fastapi import FastAPI +from fastapi.responses import HTMLResponse from learn_sql_model.api.hero import hero_router from learn_sql_model.api.user import user_router from learn_sql_model.api.websocket import web_socket_router -# from fastapi_socketio import SocketManager - - app = FastAPI() -# socket_manager = SocketManager(app=app) app.include_router(hero_router) app.include_router(user_router) app.include_router(web_socket_router) -# @app.sio.on("join") -# def handle_join(sid, *args, **kwargs): -# app.sio.emit("lobby", "User joined") +html = """ + + +
+Join the game with the following command. +
++ pipx run --spec git+https://github.com/WaylonWalker/learn-sql-model lsm game run +
++ You can watch player data at watch +
+ + +""" -# @app.sio.on("leave") -# def handle_leave(sid, *args, **kwargs): -# sm.emit("lobby", "User left") +@app.get("/") +async def get(): + return HTMLResponse(html) diff --git a/learn_sql_model/api/websocket.py b/learn_sql_model/api/websocket.py index a066176..962399c 100644 --- a/learn_sql_model/api/websocket.py +++ b/learn_sql_model/api/websocket.py @@ -1,16 +1,13 @@ -from contextlib import contextmanager - from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect from fastapi.responses import HTMLResponse -from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker +from rich.console import Console from sqlmodel import Session from websockets.exceptions import ConnectionClosed from learn_sql_model.api.websocket_connection_manager import manager -from learn_sql_model.config import get_config, get_session +from learn_sql_model.config import get_session from learn_sql_model.console import console -from learn_sql_model.models.hero import HeroUpdate, Heros +from learn_sql_model.models.hero import HeroDelete, HeroUpdate, Heros web_socket_router = APIRouter() @@ -21,28 +18,15 @@ html = """
+