Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import asyncio
- import pyttsx3 # module for text-to-speech
- engine = pyttsx3.init() # initialize text-to-speech engine
- async def check_time():
- current_time = datetime.datetime.now().time()
- current_hour = current_time.hour
- if current_hour >= 23 or current_hour < 7:
- engine.say("It's time to go to bed. Sweet dreams!")
- engine.runAndWait()
- elif current_hour >= 7 and current_hour < 11:
- engine.say("It's time to wake up and start your day!")
- engine.runAndWait()
- else:
- engine.say("Enjoy your day!")
- engine.runAndWait()
- async def main():
- loop = asyncio.get_running_loop()
- while True:
- loop.call_later(60, check_time) # schedule check_time to be called in 60 seconds
- await asyncio.sleep(60) # wait for 1 minute before scheduling the next call
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement