Create a simple pomodoro timer in python

Hey?

If you’re looking for a pretty useful yet simple python project, you’ve come to the right place!

For those who don’t know what a pomodoro timer is:

A pomodoro timer is a special type of timer used to increase productivity…


This content originally appeared on DEV Community and was authored by Code_Jedi

Hey?

If you're looking for a pretty useful yet simple python project, you've come to the right place!

For those who don't know what a pomodoro timer is:

A pomodoro timer is a special type of timer used to increase productivity.
It works something like this:

  • A pomodoro timer will give you ~25-30 minutes to work, then once you've finished working (thus completing 1 pomodoro), it will give you ~10 minutes to rest, then the timer will repeat the process.

To get started with making a pomodoro timer in python, you'll first need to install the "plyer" library by running pip install plyer or pip3 install plyer.

Then import these 2 libraries at the beginning of your python file:

import time
from plyer import notification

Next, define the variable which will represent the amount of pomodoros completed by the user, as well as an indicator that the pomodoro timer has started:

import time
from plyer import notification

count = 0
print("The pomodoro timer has started, start working!")

Now let's make the actual timer!

First, you'll need to put the timer in a while True: loop nested inside an if __name__ == "__main__": statement (if you're not familiar with it, here's a good explanation: https://stackoverflow.com/questions/419163/what-does-if-name-main-do):

if __name__ == "__main__":
    while True:

Next, make the first notification function which will notify the user when they've finished a pomodoro:

if __name__ == "__main__":
    while True:
        notification.notify(
            title = "Good work!",
            message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
        )
)

As you can see, this "notify()" function notifies the user that he/she has finished a pomodoro, and it indicates how many pomodoros the user has finished so far with the "count" variable.

Next, you'll need to create the "notify()" function which will notify the user once his/her 10 minutes of break time are over:

if __name__ == "__main__":
    while True:
        notification.notify(
            title = "Good work!",
            message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
        )
        notification.notify(
            title = "Back to work!",
            message = "Try doing another pomodoro...",
        )
)

Your pomodoro timer is almost finished!

The only things left to do are:

  • Set timeouts between the "notify()" functions.
  • Increment the "count" variable every time the user finishes a pomodoro.
if __name__ == "__main__":
    while True:
        time.sleep(1800)
        count += 1
        notification.notify(
            title = "Good work!",
            message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
        )
        time.sleep(600)
        notification.notify(
            title = "Back to work!",
            message = "Try doing another pomodoro...",
        )

Let me explain:

  • The first "time.sleep()" function waits 30 minutes(1800 seconds) before displaying the first notification, then before displaying the notification, the "count" variable is incremented since 30 minutes have passed, meaning that the user has done one pomodoro!
  • Finally, the second "time.sleep()" function waits 10 minutes(600 seconds) before notifying the user that his/her 10 minute break is over.

There you have it!

If you put everything together, your pomodoro timer should look something like this:

import time
from plyer import notification

count = 0
print("The pomodoro timer has started, start working!")

if __name__ == "__main__":
    while True:
        time.sleep(1800)
        count += 1
        notification.notify(
            title = "Good work!",
            message = "Take a 10 minute break! You have completed " + str(count) + " pomodoros so far",
        )
        time.sleep(600)
        notification.notify(
            title = "Back to work!",
            message = "Try doing another pomodoro...",
        )

Byeeeee?


This content originally appeared on DEV Community and was authored by Code_Jedi


Print Share Comment Cite Upload Translate Updates
APA

Code_Jedi | Sciencx (2021-07-19T09:11:40+00:00) Create a simple pomodoro timer in python. Retrieved from https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/

MLA
" » Create a simple pomodoro timer in python." Code_Jedi | Sciencx - Monday July 19, 2021, https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/
HARVARD
Code_Jedi | Sciencx Monday July 19, 2021 » Create a simple pomodoro timer in python., viewed ,<https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/>
VANCOUVER
Code_Jedi | Sciencx - » Create a simple pomodoro timer in python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/
CHICAGO
" » Create a simple pomodoro timer in python." Code_Jedi | Sciencx - Accessed . https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/
IEEE
" » Create a simple pomodoro timer in python." Code_Jedi | Sciencx [Online]. Available: https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/. [Accessed: ]
rf:citation
» Create a simple pomodoro timer in python | Code_Jedi | Sciencx | https://www.scien.cx/2021/07/19/create-a-simple-pomodoro-timer-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.