-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
executable file
·37 lines (30 loc) · 997 Bytes
/
test.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
#!/usr/bin/env python3
import yamlradio
import http
import urllib
import sys
import yaml
import time
import os
def main():
print("Testen of alle URL's nog online zijn.")
print("200 = online.")
loaded_yaml = os.path.join(os.path.dirname(__file__), "./yamlradio/zenders.yml")
with open(loaded_yaml, "r") as f:
zenderdict = yaml.load(f)
urllijst = [combinatie["url"] \
for combinatie in zenderdict]
for url in urllijst:
try:
print("{}: {}".format(url,urllib.request.urlopen(url).getcode()))
except urllib.error.HTTPError:
print("{} offline!".format(url))
sys.exit(1)
except http.client.BadStatusLine:
print("{} badstatusline!".format(url))
sys.exit(1)
except (TimeoutError, urllib.error.URLError):
print("{} timeout!".format(url))
sys.exit(1)
if __name__ == "__main__":
main()