Advertisement
skip420

time

Jun 16th, 2022
1,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import time
  2. import urllib.request
  3. import urllib.error
  4.  
  5. def uptime_bot(url):
  6.     while True:
  7.         try:
  8.             conn = urllib.request.urlopen(url)
  9.         except urllib.error.HTTPError as e:
  10.             # Email admin / log
  11.             print(f'HTTPError: {e.code} for {url}')
  12.         except urllib.error.URLError as e:
  13.             # Email admin / log
  14.             print(f'URLError: {e.code} for {url}')
  15.         else:
  16.             # Website is up
  17.             print(f'{url} is up')
  18.         time.sleep(60)
  19.  
  20. if __name__ == '__main__':
  21.     url = 'http://www.google.com/py'
  22.     uptime_bot(url)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement