Desktop Notifier Application Using Python in 5 Minutes | Towards Data Science

Have you ever tried to create a desktop notifications application based on your needs? do you know you can do this in a few simple steps using python?
Don't worry, let's do this from scratch, in this article we will be creating a desktop notification application for getting the daily stats of the dreadful coronavirus.
What you learn in this article
Installing required python packages.Reading the coronavirus data from the web.Creating a desktop notifier application.Making your program run in the background.
Installing required python packages.
Reading the coronavirus data from the web.
Creating a desktop notifier application.
Making your program run in the background.
we need to download two important packages for this application.
Note: you need to type this two commands in command prompt if you are using Windows or terminal if you are using Linux
requests (for fetching data from the web)
requests (for fetching data from the web)
 pip install requests
2. plyer (for creating notifications on your PC)
pip install plyer
we can fetch the coronavirus data using the URL provided below, you are free to replace the country name with your own country name, for this application we will be using India’s coronavirus data.
https://corona-rest-api.herokuapp.com/Api/india
the website looks like this
By now, we have got all the tools required to build this application, so now let's code this application
Note: It will be easier if you code this in offline compiler than online compiler because in the later stages of this article we will be making this application run as background process in your PC, if you are running in online compiler then you need to download the file which is not necessary in offline compiler. I will suggest to use Visual Studio.
part1 ( importing libraries)
part2 (retrieving the data from the web)
part3 (creating custom notification)
That’s it, we are ready to run our application before we actually run our application you need to know some changes you can make to make your application customized according to your needs.
timeout — tells how much time a notification should show up on thedesktop
time.sleep ()— tells after what interval of time the notification should popup
you can find the icon I used here
Here is how you see your notification after running your application.
So you finally created a python application and it runs fine when you go and run it. But don't you think this is a tedious job, every time running your application to get a notification?
Here is a solution, you can make this automated by running your application as a background process in your PC.
Just follow this simple command to make your application run in the background, note you need to type this command in command prompt in case you are using Windows and terminal in case you are using Linux.
Note: replace the <your-file-name-here> with your file name
pythonw.exe .\<your-file-name-here>example pythonw.exe .\desktopNotifier.py
That's it your application now starts running in the background
open task manager in your pc and you can see that in background process you can see python is running
That’s simple, in the task manager kill the process named python. If you feel any difficulty in stoping the notification please feel free to post your difficulty in the comments section of this article.
Daily notification to take medicine.Hourly notification to drink water.
Daily notification to take medicine.
Hourly notification to drink water.
and many more, it’s completely up to you how to use this application.
I hope this article had created interest in you to create your own customized desktop notification application. This application works for any kind of operating system be it Windows or Linux or Mac. If you want a simpler desktop notification application, please feel free to ask in the comment section of this article