-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.py
37 lines (30 loc) · 1.21 KB
/
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
import socket
import time
import urllib.request, urllib.error, urllib.parse
test = 1
delay_time = 1
#Display active IP address for builder to open up web browser to configure.
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
apurl = 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=1.5&stationString=KFLG,%20KSEZ'
#apurl = 'http://www.livesectional.com'
if test == 0:
while True: #check internet availability and retry if necessary. If house power outage, map may boot quicker than router.
try:
s.connect(("8.8.8.8", 80))
print('Internet Available')
break
except:
print('Internet NOT Available')
time.sleep(delay_time)
pass
else:
while True: #check internet availability and retry if necessary. If house power outage, map may boot quicker than router.
content = urllib.request.urlopen(apurl).read()
try:
content = urllib.request.urlopen(apurl).read()
print('Internet Available')
break
except:
print('Internet NOT Available')
time.sleep(delay_time)
pass