Created
February 27, 2017 13:41
-
-
Save kartikayx/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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