Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished #871

Open
wants to merge 3 commits into
base: community
Choose a base branch
from
Open

Finished #871

wants to merge 3 commits into from

Conversation

zambam5
Copy link

@zambam5 zambam5 commented Jul 19, 2023

Difficulty level (1-10): [1]
Estimated time spent (hours): [1]
Completed (yes/no): [Yes]
I stretched my coding skills (if yes what did you learn?): [I chose to figure out how to make a notification sound when the timer ends, something I had never considered doing before.]
Other feedback (what can we improve?): []

Copy link
Collaborator

@pmayd pmayd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work, but room for improvement and refactoring :)

from datetime import datetime, timedelta
from time import sleep

if platform.system() == "Windows":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way of doing it, platform acnostic, is to just do the import and catch a ModuleNotFoundError with a try except

from winsound import Beep


def pomodoro_timer(duration: int = 20, beep: bool = False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you are using type hints, annotate the whole function and that means also the return value.

Take a duration and begin a timer loop
"""
duration_delta = timedelta(minutes=duration)
d = datetime.now()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names should be speaking and have a meaning, this is not a good name :)

from winsound import Beep


def pomodoro_timer(duration: int = 20, beep: bool = False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name for duration would be minutes in this case

print("Starting timer " + str(d), "\r\nTimer will stop at " + str(d_))
sleep(duration_delta.seconds)
if beep:
Beep(frequency=500, duration=50)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is problematic because You do not check for the platform again, so this will fail ok all platforms where Beep is not available but beep is set to True

beep = False
else:
beep = True
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set beep to false before the user input and only set it to True when the user says yes, saves you one else branch

again = input(
'Do you want to start the timer again? Answer "yes" or "no" only '
)
if again == "yes":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to check here, you can completely omit this branch, only check for when you want to do something. Here you want to do something if the user does not want to continue so only check for "no"

Copy link
Collaborator

@pmayd pmayd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work but room for improvement:)

zambam5 and others added 2 commits July 20, 2023 22:35
Needed to change a yes to a no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants