Open a website automatically at a specific time in Python
In this tutorial, we will learn how to create a Python program that will automatically open an URL or webpage at a specific given time on our browser. We all know how the alarm works. In simple words, an alarm that we set on our smartphones rings a particular song or tone termed as alarm tone at the particular time which is specified by the user. A website alarm works in a similar way. So, What is the working of a website alarm? How we can create one using Python code? How we can set a website to be opened? All such questions are answered in this article. So, let’s understand how to create a website alarm using Python.
A website alarm opens a specific website at a particular time specified by the user. The website can be any URL of the user’s choice. In the given program user provides the URL of the website he wants to open as an input. In a similar way, the user feeds the desired time of opening as an input to the program. Then, in the backend program compares the desired time with the current time. During this period it continuously displays the current time. When the current time becomes the same as the desired time a message is shown. Hence, after displaying the message program opens the default browser of the system. And in a new tab, the desired URL opens and hence, the program completes it’s execution and terminates.
Hence, we can say that the desired URL replaces the alarm tone and the system of the user replaces a smartphone.
Python program to open a website at a specific time automatically
#Python program to create a website alarm # Import the webbrowser and time module import webbrowser import time # Taking website to be opened as input link = input("Enter the link to website you want to open ->") # Taking alarm time from the user alarm = input("Set the website alarm time as (Format:- HH:MM:SS)(24 hour format) ->") # This is the actual time that we will use to print. Current_time = time.strftime("%H:%M:%S") # Printing current time untill alarm time while (Current_time != alarm): print ("Waiting, the current time is " + Current_time +" :-( " ) Current_time = time.strftime("%H:%M:%S") time.sleep(1) # Opening the webpage at alarm time if (Current_time == alarm): print ("WEBSITE IS OPENING :D") webbrowser.open(link)
The time format used in the code is 24-hour format. So, while entering the alarm time we should always enter time in 24-hour format to get desired results.
MORE TO READ: