0
点赞
收藏
分享

微信扫一扫

利用 Python设置闹钟 —— 2022/2/15

设置闹钟

pip install playsound -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
from datetime import datetime
from playsound import playsound

alarm_time = input("Enter the time of alarm to be set(HH:MM:SS:pp):")
alarm_hour = alarm_time[0:2]
alarm_minute = alarm_time[3:5]
alarm_seconds = alarm_time[6:8]
alarm_period = alarm_time[9:11].upper()

while True:
    now = datetime.now()
    current_hour = now.strftime('%H')
    current_minute = now.strftime('%M')
    current_seconds = now.strftime('%S')
    current_period = now.strftime('%p')
    if alarm_period == current_period:
        if alarm_hour == current_hour:
            if alarm_minute == current_minute:
                if alarm_seconds == current_seconds:
                    print('Wake up!')
                    # 不推荐使用网易云 .mp3文件
                    playsound('艾辰 - 吻得太逼真.mp3')
                    break
举报

相关推荐

0 条评论