-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
58 lines (41 loc) · 1.15 KB
/
client.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
###################################
# UOF-STATUS-CLIENT-PY #
# (c) 2023 THE UNIVERSITY OF FOOL #
# -licensed under MIT license- #
###################################
import requests
import time
# 回报服务器状态的间隔,以秒为单位
_interval = 60
# 回报状态类型(只在特殊情况下修改)
_status = True
# 客户端 token
_token = ""
# 客户端 ID
_id = 1
# status 服务器 api 地址
_serverIp = "http://127.0.0.1:4044/api"
##################################
timeStarted = time.time()
counter = 0
def update2server(i, t, s):
data = {
"serverId": i,
"token": t,
"online": s
}
try:
r = requests.post(f"{_serverIp}/status/put", json=data)
if(r.status_code != 200):
print(data)
print(f"在上报数据时发生了错误。code = {r.status_code}")
print(r.text)
except Exception as e:
print('发生了内部错误。')
print(str(e))
# 循环体
while True:
counter += 1
print(f"Sending #{counter}, uptime = {time.time()-timeStarted}")
update2server(_id, _token, _status)
time.sleep(_interval)