Skip to content

Instantly share code, notes, and snippets.

@alphaguy4
Created February 27, 2017 13:41
Show Gist options
  • Save alphaguy4/49bddbff31abf17fee55ccaa7ad0a401 to your computer and use it in GitHub Desktop.
Save alphaguy4/49bddbff31abf17fee55ccaa7ad0a401 to your computer and use it in GitHub Desktop.
Python Script which check if a given website is online and start a new session in default browser.
"""
Simple Script to inform you when the website is up and automatically starts a new session in default browser
This script assumes the url entered is valid.
Author:alphaguy4
"""
import requests
import sys
import time
import webbrowser
from urllib.parse import urlparse
from subprocess import call
url = ""
domain = ""
args = sys.argv
if len(args) == 1:
url = input('Enter the url : ')
else:
url = args[1]
domain = urlparse(url).netloc
speech = "Sir, website is now online."
while True:
try:
res = requests.get(url)
if res.status_code == requests.codes.ok:
print("200\n" + domain + " is now online")
webbrowser.open(url,new=2)
for i in range(2):
call(["notify-send",domain,"is now online"])
call(["espeak",speech]);
time.sleep(3)
break
time.sleep(10)
except requests.ConnectionError as e:
print("Check Your internet connection!!")
sys.exit(1)
else:
print("Some Error Occured!!")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment