-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_websites.py
More file actions
30 lines (24 loc) · 857 Bytes
/
check_websites.py
File metadata and controls
30 lines (24 loc) · 857 Bytes
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
from messaging_service import MessagingService
import requests
import json
# path to websites JSON file
WEBSITES_FILE = './websites.json'
# initiate messaging service
messager = MessagingService('./config.json', "check_websites")
# will be populated by parsing websites JSON file
urls = []
# open and parse websites JSON file to get URLs array
try:
with open(WEBSITES_FILE) as websites_file:
urls = json.load(websites_file).get("urls")
except:
messager.send_error("Failed to open and parse website URLs file.")
for url in urls:
# ping URL to get response
try:
response = requests.get(url)
status = response.status_code
if status != 200:
messager.send("Warning! Received status code " + str(status) + " from URL " + url)
except:
messager.send_error("Failed to connect to " + url)