forked from RemingtonDev/New-World-Server-Status-Scraper-FR
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.py
131 lines (109 loc) · 4.88 KB
/
functions.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from discord_webhook import DiscordWebhook, DiscordEmbed
from copy import deepcopy
def discord_webhook(webhook_url, region, server, new_status, status_url,
message):
if new_status == "✅":
status_color = "00cf00"
elif new_status == "❌":
status_color = "ff0000"
elif new_status == "🔒":
status_color = "FFA500"
elif new_status == "🔧":
status_color = "696969"
else:
status_color = "ffaa00"
webhook = DiscordWebhook(url=webhook_url, rate_limit_retry=True)
embed = DiscordEmbed(title="Status der New World Server",
description=message,
color=status_color,
url=status_url)
embed.add_embed_field(name="Region", value=region)
embed.add_embed_field(name="Server", value=server)
embed.add_embed_field(name="Status", value=new_status)
webhook.add_embed(embed)
response = webhook.execute()
return response
def switch(old_status, new_status, webhook_url, region, server, url):
if new_status == "✅":
if old_status == "null":
discord_webhook(webhook_url, region, server, new_status, url, "Der folgende Server ist gerade in der "
"Liste aufgetaucht:")
elif old_status != new_status:
discord_webhook(webhook_url, region, server, "✅ (Online)", url, "Der folgende Server ist jetzt online:")
elif new_status == "❌":
if old_status == "null":
discord_webhook(webhook_url, region, server, new_status, url, "Der folgende Server ist gerade in der "
"Liste aufgetaucht:")
elif old_status != new_status:
discord_webhook(webhook_url, region, server, "❌ (Offline)", url, "Der folgende Server ist jetzt offline:")
elif new_status == "🔧":
if old_status == "null":
discord_webhook(webhook_url, region, server, new_status, url, "Der folgende Server ist gerade in der "
"Liste aufgetaucht:")
elif old_status != new_status:
discord_webhook(webhook_url, region, server, "🔧 (Wartung)", url, "Der folgende Server wird gerade gewartet:")
elif new_status == "🔒":
if old_status == "null":
discord_webhook(webhook_url, region, server, new_status, url, "Der folgende Server ist gerade in der "
"Liste aufgetaucht:")
elif old_status != new_status:
discord_webhook(webhook_url, region, server, "🔒 (Voll)", url, "Der folgende Server ist jetzt voll:")
elif new_status == "null":
discord_webhook(
webhook_url, region, server, "💨", url, "Der folgende Server ist gerade aus der Liste verschwunden:")
def deep_diff(x, y, parent_key=None, exclude_keys=[], epsilon_keys=[]):
EPSILON = 0.5
rho = 1 - EPSILON
if x == y:
return None
if parent_key in epsilon_keys:
xfl, yfl = float_or_None(x), float_or_None(y)
if xfl and yfl and xfl * yfl >= 0 and rho * xfl <= yfl and rho * yfl <= xfl:
return None
if type(x) != type(y) or type(x) not in [list, dict]:
return x, y
if type(x) == dict:
d = {}
for k in x.keys() ^ y.keys():
if k in exclude_keys:
continue
if k in x:
d[k] = (deepcopy(x[k]), None)
else:
d[k] = (None, deepcopy(y[k]))
for k in x.keys() & y.keys():
if k in exclude_keys:
continue
next_d = deep_diff(x[k],
y[k],
parent_key=k,
exclude_keys=exclude_keys,
epsilon_keys=epsilon_keys)
if next_d is None:
continue
d[k] = next_d
return d if d else None
d = [None] * max(len(x), len(y))
flipped = False
if len(x) > len(y):
flipped = True
x, y = y, x
for i, x_val in enumerate(x):
d[i] = deep_diff(y[i],
x_val,
parent_key=i,
exclude_keys=exclude_keys,
epsilon_keys=epsilon_keys) if flipped else deep_diff(
x_val,
y[i],
parent_key=i,
exclude_keys=exclude_keys,
epsilon_keys=epsilon_keys)
for i in range(len(x), len(y)):
d[i] = (y[i], None) if flipped else (None, y[i])
return None if all(map(lambda x: x is None, d)) else d
def float_or_None(x):
try:
return float(x)
except ValueError:
return None