diff options
author | meltland <[email protected]> | 2025-03-07 23:41:45 -0500 |
---|---|---|
committer | meltland <[email protected]> | 2025-03-07 23:41:45 -0500 |
commit | d9b1580e853978f322a1bf7dee910eb1077e3d46 (patch) | |
tree | c27c64effefc3e5828f6e07bf3798d32bffb4ab0 |
Initial commit
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | db.py | 26 | ||||
-rw-r--r-- | main.py | 23 |
3 files changed, 50 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/db.py b/db.py new file mode 100644 index 0000000..de28d7a --- /dev/null +++ b/db.py @@ -0,0 +1,26 @@ +import json +import os +from passlib.hash import scrypt +from pymongo.mongo_client import MongoClient +from pymongo.server_api import ServerApi +from dotenv import load_dotenv + +load_dotenv() + +uri = os.getenv("MONGODB_URL") + +# Create a new client and connect to the server +client = MongoClient(uri, server_api=ServerApi('1')) + +# Send a ping to confirm a successful connection +try: + client.admin.command('ping') + print("Connected to MongoDB!") +except Exception as e: + print(e) + exit() + +database = client["SoktDeer"] +postsd = database["Posts"] +usersd = database["Users"] +inboxd = database["Inbox"] \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..07eac1a --- /dev/null +++ b/main.py @@ -0,0 +1,23 @@ +import asyncio +import logging +from websockets.asyncio.server import serve + +addr = "localhost" +port = 3636 + +logging.basicConfig(level=logging.INFO) + +async def handler(websocket): + await websocket.send("Hello") + miw = 0 + async for message in websocket: + miw += 1 + async for message in websocket: + print(str(websocket)) + await websocket.send(message) + +async def main(): + async with serve(handler, addr, port) as server: + await server.serve_forever() + +asyncio.run(main()) \ No newline at end of file |