This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funciones.py
97 lines (72 loc) · 2.42 KB
/
funciones.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import urllib.request, json, os.path
def JsonPostRequest(jsoncontent, url):
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json; charset=utf-8')
jsondata = json.dumps(jsoncontent)
jsondataasbytes = jsondata.encode('utf-8') # needs to be bytes
req.add_header('Content-Length', len(jsondataasbytes))
return urllib.request.urlopen(req, jsondataasbytes)
def RegisterGame(port, game, gamedisplayname):
print("Registering '%s'..." % gamedisplayname)
event = {
"game": game,
"game_display_name": gamedisplayname
}
url = "http://127.0.0.1:"+str(port)+"/game_metadata"
JsonPostRequest(event, url)
def RegisterEvent(event, port):
print("Registering event...")
url = "http://127.0.0.1:"+str(port)+"/register_game_event"
JsonPostRequest(event, url)
def BindEvent(event, port):
print("Binding event...")
url = "http://127.0.0.1:"+str(port)+"/bind_game_event"
JsonPostRequest(event, url)
def GameEvent(event, port):
url = "http://127.0.0.1:"+str(port)+"/game_event"
JsonPostRequest(event, url)
def RemoveEvent(port, game, eventname):
print("Removing event '%s' for '%s'..." % (eventname, game))
event = {
"game": game,
"event": eventname
}
url = "http://127.0.0.1:"+str(port)+"/remove_game_event"
JsonPostRequest(event, url)
def RemoveGame(port, game):
print("Removing '%s'..." % game)
event = {
"game": game
}
url = "http://127.0.0.1:"+str(port)+"/remove_game"
JsonPostRequest(event, url)
def GetSSE3ListeningPort(corePropsPath='C:\\ProgramData\\SteelSeries\\SteelSeries Engine 3\\coreProps.json'):
if os.path.isfile(corePropsPath):
with open(corePropsPath) as f:
data = json.load(f)
addr = data["address"]
addr.split(":")[1]
return int(addr.split(":")[1])
else:
print("ERROR: File '%s' not found." % corePropsPath)
return False
def BindHealthEvent(port, game, device_type, zone):
HealthEvent = {
"game": game,
"event": "HEALTH",
"min_value": 0,
"max_value": 100,
"icon_id": 1,
"handlers": [
{
"device-type": device_type,
"zone": zone,
"color": { "gradient": {"zero": {"red": 255, "green": 0, "blue": 0},
"hundred": {"red": 0, "green": 255, "blue": 0} } },
"mode": "color"
}
]
}
BindEvent(HealthEvent, port)
def Porcentaje(CurrentHealth, MaxHealth):
return (100*CurrentHealth)/MaxHealth