From 7d780e820e64d88799b8a9ebf13e7e1cfe871362 Mon Sep 17 00:00:00 2001 From: Tyler Z Date: Tue, 18 Jul 2023 22:30:55 -0500 Subject: [PATCH 1/3] Finished --- 52/zambam5/timer.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 52/zambam5/timer.py diff --git a/52/zambam5/timer.py b/52/zambam5/timer.py new file mode 100644 index 00000000..9cba5bda --- /dev/null +++ b/52/zambam5/timer.py @@ -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(duration: int = 20, beep: bool = False): + """ + Take a duration and begin a timer loop + """ + duration_delta = timedelta(minutes=duration) + d = datetime.now() + d_ = d + duration_delta + print("Starting timer " + str(d), "\r\nTimer will stop at " + str(d_)) + sleep(duration_delta.seconds) + if beep: + Beep(frequency=500, duration=50) + pass + + +def main(): + if platform.system() == "Windows": + b_question = input( + 'Do you want the timer to beep when finished? Answer "yes" or "no" ' + ) + if b_question == "no": + beep = False + else: + beep = True + else: + 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 == "yes": + continue + else: + print("Ending the loop, hope you got some good work done!") + sleep(0.5) + break + + +if __name__ == "__main__": + main() From ed2b958b0a9fdbe923642f76b662dad3f5aa9c7a Mon Sep 17 00:00:00 2001 From: Tyler Z Date: Thu, 20 Jul 2023 22:35:04 -0500 Subject: [PATCH 2/3] Changes based on feedback --- 52/zambam5/timer.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/52/zambam5/timer.py b/52/zambam5/timer.py index 9cba5bda..8dcc25c1 100644 --- a/52/zambam5/timer.py +++ b/52/zambam5/timer.py @@ -7,28 +7,30 @@ from winsound import Beep -def pomodoro_timer(duration: int = 20, beep: bool = False): +def pomodoro_timer(minutes: int = 20, beep: bool = False) -> None: """ - Take a duration and begin a timer loop + Take a duration in minutes and sleep for that amount of time """ - duration_delta = timedelta(minutes=duration) - d = datetime.now() - d_ = d + duration_delta - print("Starting timer " + str(d), "\r\nTimer will stop at " + str(d_)) - sleep(duration_delta.seconds) - if beep: + 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) pass -def main(): +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 == "no": - beep = False - else: beep = True else: beep = False @@ -37,9 +39,7 @@ def main(): again = input( 'Do you want to start the timer again? Answer "yes" or "no" only ' ) - if again == "yes": - continue - else: + if again == "no": print("Ending the loop, hope you got some good work done!") sleep(0.5) break From 20b026844d262d419077076487d50b05a412f3b1 Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 20 Jul 2023 22:46:07 -0500 Subject: [PATCH 3/3] Update timer.py Needed to change a yes to a no --- 52/zambam5/timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/52/zambam5/timer.py b/52/zambam5/timer.py index 8dcc25c1..eec15e09 100644 --- a/52/zambam5/timer.py +++ b/52/zambam5/timer.py @@ -30,7 +30,7 @@ def main() -> None: b_question = input( 'Do you want the timer to beep when finished? Answer "yes" or "no" ' ) - if b_question == "no": + if b_question == "yes": beep = True else: beep = False