This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ChatGPT to write python
#1
Anyone tried it? Might actually come in very handy--

chat.openai.com

 ask-
"write some python to receive websocket data"

reply "Here is an example of how to receive data from a websocket using the websockets library in Python:"

Code:
import asyncio
import websockets

async def receive_data(websocket):
    while True:
        data = await websocket.recv()
        print(f"Received data: {data}")

async def main(uri):
    async with websockets.connect(uri) as websocket:
        await receive_data(websocket)

uri = "ws://your-websocket-url"
asyncio.get_event_loop().run_until_complete(main(uri))
Reply


Messages In This Thread
ChatGPT to write python - by PaddyB - 2023-02-01, 12:40 PM
RE: ChatGPT to write python - by Sailoog - 2023-02-01, 04:27 PM
RE: ChatGPT to write python - by PaddyB - 2023-02-02, 05:33 AM
RE: ChatGPT to write python - by PaddyB - 2023-02-02, 10:35 AM
RE: ChatGPT to write python - by Sailoog - 2023-02-02, 01:47 PM
RE: ChatGPT to write python - by PaddyB - 2023-04-04, 02:40 PM
RE: ChatGPT to write python - by MigGat - 2023-04-06, 08:57 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)