Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Set And Forget Python Script To Monitor Offline Site

$
0
0

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('https://www.example.co.uk/')
... if r.status_code == 200:
... webbrowser.open('https://www.example.co.uk/')
... 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).


Viewing all articles
Browse latest Browse all 9596

Trending Articles