Python Project To Improve Your Productivity For The New Year | by Bharath K | Towards Data Science

The new year is approaching very soon, and I think most people are glad that 2020 is almost over! Most people are excited and are welcoming the next year of 2021. Hence, this upcoming New Year presents all of us an opportunity to build an incredible Python project that will be useful for the rest of the year.
With every New Year, there comes some resolution or resolutions that everyone plans they will follow them. And I do follow it for a clean few days and then get back to my usual routine. All my plans go to the bin! And get shifted over to the Next Year instead.
However, it would be awesome to develop a Python project that would consistently remind me of my plans and keep telling me to follow my ideas and schedule that I have planned for the rest of the year!
In this project, this is exactly what we will be trying to achieve in our article today! We will be developing a simple but useful reminder application that will consistently remind us about the aims and goals that we have planned for our New Year.
The main objective of the reminder notification application we will develop today is to consistently remind us about the various things we need to accomplish during the course of the entire day. This project is similar to a To-Do List, where we have a set of goals to achieve. And the reminder app will constantly notify us about the various tasks we need to do and actions to complete throughout the course of the day.
For the purpose of this article, I will be alerting myself to take a break after every hour. Since I spend most of my time on the PC, it would be a great idea for me to take a break every now and then. However, your message and alert can be absolutely anything you desire! You can have a list of things you need to complete within the day, week, or month, and the reminder application will constantly remind you about the same.
As discussed in the problem statement, our goal is to ensure that the specific action is reminded to us in due time so that it can be completed within the exact duration.
For the purpose of completing the task exactly on time, we need to also import the time module, which will serve this purpose. The time module can be imported with the following command —
import time
The time is a pre-built library module in Python and can be easily accessed with the above command. It is used to handle any kind of task that is related to time. The time module has a lot of functions for performing specific tasks. We will only dwell deeper into the time.sleep() function for the requirements of this article.
Suspend execution of the calling thread for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.
Changed in version 3.5: The function now sleeps at least secs even if the sleep is interrupted by a signal, except if the signal handler raises an exception. To learn more about the time module check out the official documentation here.
With the time module already discussed, the only other module we will require for the completion of this task is the plyer module, which can be installed with the following simple command —
The pip install plyer command should install the second and final module required for performing this task.
Plyer is a Python library for accessing features of your hardware or other platforms.
Once the installation of the plyer module is complete, you can make use of the notification class in this library for the creation of our reminder application. This notification option allows us to run the script with the task scheduler. The final imports of all the libraries required for this task should look similar to the code block below:
import timefrom plyer import notification
On the Windows platform, we have an option available to us called the task scheduler. Task Scheduler is a component of Microsoft Windows that provides the ability to schedule the launch of programs or scripts at pre-defined times or after specified time intervals like job scheduling.
Extra Information:
The Task Scheduler service works by managing Tasks; Task refers to the action (or actions) taken in response to trigger(s). A task is defined by associating a set of actions, which can include launching an application or taking some custom-defined action, to a set of triggers, which can either be time-based or event-based.
In addition, a task also can contain metadata that defines how the actions will be executed, such as the security context the task will run in. Tasks are serialized to .job files and are stored in the special folder titled Task Folder, organized in subdirectories.
Programmatically, the task folder is accessed using the ITaskFolder interface or the TaskFolder scripting object and individual tasks using the IRegisteredTask interface or RegisteredTask object.
Building the simple code block:
We already discussed about the notification class. This class offers us the notify function. The information and syntax of the notify method is as discussed below.
notify (title='', message='', app_name='', app_icon='', timeout=10, ticker='', toast=False)
title (str) — Title of the notification
message (str) — Message of the notification
app_name (str) — Name of the app launching this notification
app_icon (str) — Icon to be displayed along with the message
timeout (int) — time to display the message for, defaults to 10
ticker (str) — text to display on status bar as the notification arrives
toast (bool) — simple Android message instead of full notification
Now that we have a brief idea of the function in the notification class, let us understand how we can implement this. The below code block is the main procedure to define your tasks at hand.
if __name__ == "__main__":    while True:        notification.notify(            title = "ALERT!!!",            message = "Take a break! It has been an hour!",            timeout = 10        )        time.sleep(3600)
Now, we will proceed to understand each line in the above code block step by step.
The if __name__ == “__main__”: is an extremely important concept in Python. Before executing code, Python interpreter reads source file and define few special variables/global variables. If the python interpreter is running that module (the source file) as the main program, it sets the special __name__ variable to have a value “__main__”.
If this file is being imported from another module, __name__ will be set to the module’s name. Module’s name is available as value to __name__ global variable. Refer to the following website for further information of this concept in more detail.
We will then assign a while loop to run the code as long as it is True. This basically means that the code block will run for the time interval that we have set for running the program. Here, I have set the time required to run the program as 3600 seconds i.e. a total of one hour. After each hour, I will receive my reminder notification.
Finally, we have the notification class with the notify method defined. We will set all the required parameters, as suggested in the code block. You are free to change the contents of the parameters according to your schedule or the tasks you have to perform. You can also determine how long you want the notification to remain on the display screen with the timeout instance.
You can have multiple scripts running on your Desktop background that will consistently remind and alert you about the various tasks you need to perform throughout the course of the day, week, month, or year.
To Run the script just run the following command in the command prompt as shown in the below code line. Make sure to replace the main.py with the name of your script file.
pythonw .\main.py
You can also simply use the python main.py command as well to run the script. After an hour you should receive the following alert.
You will continuously receive these alerts every hour or until the time stipulation that you have set because of the while loop that is defined in the code. In the next section, you can analyze and copy and paste the entire code with the GitHub Gist provided.
Final Code Block:
In this article, we discussed how to build a reminder app that will help to timely notify us about the various commitments we have as well as will act as a successful means of reminding us about these tasks that we need to complete.
The project discussed in this article is quite simple but useful nonetheless. It should be a great way for beginners who are interested in the Python programming language to immerse themselves into this field and build tons of cool projects related to the same.
With the year 2020 finally coming to an end, I wish you all good luck for the epic future year of 2021. I hope all of you will have a wonderful upcoming year and will build lots of incredible and cool Python and Data Science projects! Let us all make some resolutions to have a productive and innovative New Year!
If you guys liked this article, please feel free to check out some of my other stories that you might enjoy also reading!
towardsdatascience.com
towardsdatascience.com
towardsdatascience.com
towardsdatascience.com
towardsdatascience.com
Thank you all for sticking on till the end. I hope you guys enjoyed reading this article. I wish you all have a wonderful day ahead!