Set And Forget Python Script To Monitor Offline Site

Datetime:2016-08-22 22:28:36         Topic: Python          Share        Original >>
Here to See The Original Article!!!

I've just had a clients site go offline due to a server change, it was a quick move, so no big deal, however, I wanted to check the status of the site to see when it came back online but without having to keep checking on it - Enter a quick Python script.

While this isn't really impressive I thought I'd share is it's a good reminder of what Python can do in different circumstances - I've spent the day in and out of analysis tools, which I've built using Python for different uses, including some big data projects, and now I just used it to run a throw-away script which I wrote straight in the terminal (cmd actually).

>>> import requests
>>> import time
>>> import webbrowser
>>> while True:
...     r=requests.get('')
...     if r.status_code == 200:
...     else:
...         pass
...     time.sleep(10)

It literally just checks the site every 10 seconds and checks to see if the status code is a 200 and if it is, it opens it in a webbrowser (this is the alert part).


Put your ads here, just $200 per month.