-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: community
Are you sure you want to change the base?
Finished #871
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import platform | ||
|
||
from datetime import datetime, timedelta | ||
from time import sleep | ||
|
||
if platform.system() == "Windows": | ||
from winsound import Beep | ||
|
||
|
||
def pomodoro_timer(minutes: int = 20, beep: bool = False) -> None: | ||
""" | ||
Take a duration in minutes and sleep for that amount of time | ||
""" | ||
minutes_delta = timedelta(minutes=minutes) | ||
date_now = datetime.now() | ||
date_after_minutes = date_now + minutes_delta | ||
print( | ||
"Starting timer " + str(date_now), | ||
"\r\nTimer will stop at " + str(date_after_minutes), | ||
) | ||
sleep(minutes_delta.seconds) | ||
if beep and platform.system() == "Windows": | ||
Beep(frequency=500, duration=50) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
pass | ||
|
||
|
||
def main() -> None: | ||
if platform.system() == "Windows": | ||
beep = False | ||
b_question = input( | ||
'Do you want the timer to beep when finished? Answer "yes" or "no" ' | ||
) | ||
if b_question == "yes": | ||
beep = True | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
beep = False | ||
while True: | ||
pomodoro_timer(beep=beep) | ||
again = input( | ||
'Do you want to start the timer again? Answer "yes" or "no" only ' | ||
) | ||
if again == "no": | ||
print("Ending the loop, hope you got some good work done!") | ||
sleep(0.5) | ||
break | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
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