From aef5014e74c61afb425b3251e09026d61228f9a5 Mon Sep 17 00:00:00 2001 From: Brandon4466 Date: Mon, 5 Jun 2023 00:52:55 -0700 Subject: [PATCH] basic start: websockets setup and connecting --- main.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..dc70e60 --- /dev/null +++ b/main.py @@ -0,0 +1,37 @@ +import spotipy +import asyncio +from websockets.server import serve +from websockets.sync.client import connect + +spotify = spotipy.Spotify(auth_manager=spotipy.oauth2.SpotifyOAuth(client_id="1cb8bc27872c4bcaaad0e95f123b4f7d", client_secret="9893dfb6d9eb43eebf082f9173ce937c", + redirect_uri="http://127.0.0.1:8888/callback", scope="user-read-playback-state,user-modify-playback-state", + requests_timeout=30)) + +def startup(): + if input("Press 1 for server, 2 for client: ") == "1": + server() + else: + client() + +def server(): + async def echo(websocket): + async for message in websocket: + await websocket.send(message) + + async def main(): + async with serve(echo, "localhost", 8765): + await asyncio.Future() + + asyncio.run(main()) + +def client(): + def hello(): + with connect("ws://localhost:8765") as websocket: + websocket.send(input("Enter a message: ")) + message = websocket.recv() + print(f"Received: {message}") + + hello() + +if __name__ == "__main__": + startup() \ No newline at end of file