使用Python创建网站警报

我们使用书签来记住我们认为将来会经常使用的重要网站。 下面是一个简单的python代码,它将网站的URL作为第一个输入,将打开它的时间作为第二个输入。

null

当时间达到给定的时间值时,它会自动打开您在web浏览器中请求的URL。 在这段代码中,我们将导入两个python模块——Time和Webbrowser。

# Import the time module, it provides various time-related
# functions.
import time
# Import the webbrowser module, it is used to
# display various HTML documents to the user.
import webbrowser
# First Input: It is the time of the form
# 'Hours:Minutes:Seconds' that you'll
# use to set the alarm.
Set_Alarm = input ( "Set the website alarm as H:M:S:" )
# Second Input: It is the URL that you want
# to open on the given time.
url = input ( "Enter the website you want to open:" )
# This is the actual time that we will use to print.
Actual_Time = time.strftime( "%I:%M:%S" )
# This is the while loop that'll print the time
# until it's value will be equal to the alarm time
while (Actual_Time ! = Set_Alarm):
print ( "The time is " + Actual_Time)
Actual_Time = time.strftime( "%I:%M:%S" )
time.sleep( 1 )
# This if statement plays the role when its the
# alarm time and executes the code within it.
if (Actual_Time = = Set_Alarm):
print ( "You should see your webpage now :-)" )
# We are calling the open()
# function from the webrowser module.
webbrowser. open (url)


你可以通过 在这里 .

本文由 希瓦姆·夏尔马 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

你可以通过 在这里 .

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享