![]() |
|
[Tut] How I used Python to Automate my Daily Routine with Desktop Notifications - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Python (https://sickgaming.net/forum-83.html) +--- Thread: [Tut] How I used Python to Automate my Daily Routine with Desktop Notifications (/thread-100577.html) |
[Tut] How I used Python to Automate my Daily Routine with Desktop Notifications - xSicKxBot - 01-15-2023 How I used Python to Automate my Daily Routine with Desktop Notifications Rate this post ![]() [b]Project Description[/b] Today while working on my Python code, I suddenly realized that it’s been two hours since I have been trying to solve the bug. I was constantly looking at the screen for two hours without even realizing to take a break or drink a glass drink water. That is when I thought of creating a script that would automate my daily routine with desktop notifications. I thought of creating a script that will generate a notification after certain time intervals for the following:
Therefore, in this project, we will be learning how to automate the daily routine using desktop popup notifications. So, without further delay, let’s dive into the steps to complete our project. [b]Step 1: Install and Import the Necessary Libraries[/b] The two important libraries we need in this project are Code: win10toastCode: scheduleCode: win10toastCode: pip install win10toastOnce you have installed the win10toast module, go ahead and install the Code: scheduleCode: pip install scheduleCode: ScheduleCode: commandCode: timeCode: timeCode: import win10toast
import schedule import timeI used the ToastNotifier class from the Code: win10toastCode: show_toastCode: noti = win10toast.ToastNotifier()
noti.show_toast("Demo", "You will get a notification", duration = 10)Explanation: The first argument in the Code: show_toast[b]Step 3: Scheduling the Tasks[/b] Code: Code: schedule.every().hour.do(water)
schedule.every().hour.do(take_break)
schedule.every(10).to(15).minutes.do(work)
schedule.every().day.at("22:00").do(medicine)
schedule.every().day.at("20:00").do(backup)
while True: schedule.run_pending() time.sleep(1)Explanation: As we need to generate the notifications after certain time intervals we would use the Code: scheduleCode: sleepCode: time[b]Step 4: Creating the Task Functions[/b] Next, I created different functions that will perform different tasks when called. The function to remind me to:
Code: def water(): noti.show_toast('Time to drink water!', duration= 10)
Code: def take_break(): noti.show_toast('You have been working since one hour. Time to take a break', duration= 10)
Code: def work(): noti.show_toast('Restart your work', duration= 10)
Code: def medicine(): noti.show_toast('Time to take the medicine', duration= 15)
Code: def backup(): noti.show_toast('Take backup and end work', duration= 15)Now let’s put it all together to visualize how the entire script works : Code: import win10toast
import schedule import time noti = win10toast.ToastNotifier() def water(): noti.show_toast('Time to drink water!', duration= 10) def take_break(): noti.show_toast('You have been working since one hour. Time to take a break', duration= 10) def work(): noti.show_toast('Restart your work', duration= 10) def medicine(): noti.show_toast('Time to take the medicine', duration= 15) def backup(): noti.show_toast('Take backup and end work', duration= 15) schedule.every().hour.do(water)
schedule.every().hour.do(take_break)
schedule.every(10).to(15).minutes.do(work)
schedule.every().day.at("22:00").do(medicine)
schedule.every().day.at("20:00").do(backup) while True: schedule.run_pending() time.sleep(1)There we go! We have successfully created a wonderful automated script that will generate notifications for us, giving us prompts at certain intervals to organize our work and daily routine. I hope this project added some value and helped you in your coding quest. Stay tuned and subscribe for more interesting projects and tutorials. Do you love automating tasks with Python? Well! I do. And if you are someone who likes automation then here’s a list of few mini projects that will get you going –
|