37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
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() |