Python Project To Improve Your Productivity For The New Year
By: Bharath K
Tags: Data Science, Python, Artificial Intelligence, Programming, Productivity

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.

Syntax:

notify (title='', message='', app_name='', app_icon='', timeout=10, ticker='', toast=False)

title (str) — Title of the notification

(str) — Title of the notification message (str) — Message of the notification

(str) — Message of the notification app_name (str) — Name of the app launching this notification

(str) — Name of the app launching this notification app_icon (str) — Icon to be displayed along with the message

(str) — Icon to be displayed along with the message timeout (int) — time to display the message for, defaults to 10

(int) — time to display the message for, defaults to 10 ticker (str) — text to display on status bar as the notification arrives

(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.