Advertisement
matthewdeanmartin

go to bed, wake up program by chatgpt

Dec 18th, 2022
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import datetime
  2. import asyncio
  3. import pyttsx3  # module for text-to-speech
  4.  
  5. engine = pyttsx3.init()  # initialize text-to-speech engine
  6.  
  7. async def check_time():
  8.     current_time = datetime.datetime.now().time()
  9.     current_hour = current_time.hour
  10.  
  11.     if current_hour >= 23 or current_hour < 7:
  12.         engine.say("It's time to go to bed. Sweet dreams!")
  13.         engine.runAndWait()
  14.     elif current_hour >= 7 and current_hour < 11:
  15.         engine.say("It's time to wake up and start your day!")
  16.         engine.runAndWait()
  17.     else:
  18.         engine.say("Enjoy your day!")
  19.         engine.runAndWait()
  20.  
  21. async def main():
  22.     loop = asyncio.get_running_loop()
  23.     while True:
  24.         loop.call_later(60, check_time)  # schedule check_time to be called in 60 seconds
  25.         await asyncio.sleep(60)  # wait for 1 minute before scheduling the next call
  26.  
  27. asyncio.run(main())
  28.  
Tags: chatGPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement