File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change
1
+ import asyncio
2
+ import websockets
3
+ import sys
4
+
5
+ websocket_endpoint = 'ws://localhost:8765' # url / uro
6
+
7
+ async def connect_to_ws (msg ):
8
+ async with websockets .connect (websocket_endpoint ) as ws :
9
+ await ws .send (msg )
10
+
11
+ if __name__ == "__main__" :
12
+ msg = 'nothing here'
13
+ try :
14
+ msg = sys .argv [1 ]
15
+ except :
16
+ pass
17
+ loop = asyncio .get_event_loop ()
18
+ loop .run_until_complete (connect_to_ws (msg ))
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import websockets
3
+ import json
3
4
4
- async def webhook_handler (* args , ** kwargs ):
5
- print (args , kwargs )
6
- pass
5
+ async def webhook_handler (websocket , path ):
6
+ print (websocket , path )
7
+ async for message in websocket :
8
+ data = {}
9
+ try :
10
+ data = json .loads (message )
11
+ except :
12
+ pass
13
+ print (data .get ('data' ))
14
+ # print(message)
15
+ # pass
7
16
8
17
9
18
server = websockets .serve (webhook_handler , 'localhost' , 8765 )
You can’t perform that action at this time.
0 commit comments