-
Notifications
You must be signed in to change notification settings - Fork 0
/
wstest.py
42 lines (36 loc) · 1013 Bytes
/
wstest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import websockets
import configparser
import datetime
import random
import json
parser = configparser.ConfigParser()
parser.read_file(open(r'config.txt'))
CONFIG_TOKEN = parser.get('walking-pad-twitch', 'token')
CONFIG_IP = parser.get('walking-pad-twitch', 'ip')
print(CONFIG_TOKEN)
print(CONFIG_IP)
async def getSimulateNum(v):
print(v)
v['sp'] = random.uniform(4, 5)
v['step'] = v['step'] + 1
v['cal'] = v['cal'] + 1
v['time'] = v['time'] + 1
v['dist'] = v['dist'] + 0.01
return v
async def time(websocket, path):
values = {
'sp': 5.0,
'step': 2400,
'cal': 500,
'time': 12,
'dist': 0.5,
'mode': 'walk',
}
while True:
values = await getSimulateNum(values)
await websocket.send(str(json.dumps(values)))
await asyncio.sleep(1)
start_server = websockets.serve(time, 'localhost', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()