-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.py
34 lines (31 loc) · 1.02 KB
/
scrape.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
import json
import requests
# Send a GET request to the website
url = "https://raw.githubusercontent.com/rackerlabs/rs-flex-uptime/refs/heads/master/README.md"
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
resp = str(response.content)
uptxt = 'All systems operational'
degradedtxt = 'Degraded performance'
fullouttxt = 'Complete outage'
partialouttxt = 'Partial outage'
outdict = {"schemaVersion": 1,
"label": "status",
"message": "operational",
"color": "brightgreen"
}
if degradedtxt in resp:
outdict['message'] = 'degraded'
outdict['color'] = 'yellow'
elif fullouttxt in resp:
outdict['message'] = 'outage'
outdict['color'] = 'red'
elif partialouttxt in resp:
outdict['message'] = 'partial outage'
outdict['color'] = 'orange'
else:
print("Failed to retrieve the website")
f = open("status.json", "w")
f.write(json.dumps(outdict))
f.close()