From 4ff39cf1f708fcf1988f70f1e87d4ff38f763668 Mon Sep 17 00:00:00 2001 From: Laura Jordana Date: Sun, 6 Dec 2020 22:49:30 -0800 Subject: [PATCH 1/2] day 3 challenge pomodoro timer --- 52/lauramariel/pomodoro.py | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 52/lauramariel/pomodoro.py diff --git a/52/lauramariel/pomodoro.py b/52/lauramariel/pomodoro.py new file mode 100644 index 000000000..40cf40c11 --- /dev/null +++ b/52/lauramariel/pomodoro.py @@ -0,0 +1,49 @@ +import time +from datetime import datetime +from datetime import timedelta + +def timer(timer_type): + if timer_type == "pomodoro": + endtime = datetime.now() + timedelta(minutes=25) + elif timer_type == "short_break": + endtime = datetime.now() + timedelta(minutes=5) + elif timer_type == "long_break": + endtime = datetime.now() + timedelta(minutes=10) + else: + endtime = "" + print(f"Error") + + while (datetime.now().replace(microsecond=0) != endtime.replace(microsecond=0)): + timeleft = endtime - datetime.now() + timeleft = str(timeleft).split(".")[0] + print(f"{timeleft}", end='\r') + time.sleep(1) + + print(f"{timer_type} done!") + return True + +def main(): + pomodoro_count = 0 + while True: + intervals = ["pomodoro", "break"] + + for timer_type in intervals: + + if timer_type == "pomodoro": + pomodoro_count += 1 + print(f"It's work time! Pomodoro #{pomodoro_count}") + + if timer_type == "break": + # determine whether it's a short or long break + if pomodoro_count < 4: + # it's a short break + timer_type = "short_break" + else: + timer_type = "long_break" + pomodoro_count = 0 + print(f"Starting {timer_type}!") + + timer(timer_type=timer_type) + +if __name__ == "__main__": + main() \ No newline at end of file From 14896a89551014faaf93bfd7f1e4669acd9dd6b7 Mon Sep 17 00:00:00 2001 From: Laura Jordana Date: Sun, 6 Dec 2020 22:55:41 -0800 Subject: [PATCH 2/2] clean up --- 52/lauramariel/pomodoro.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/52/lauramariel/pomodoro.py b/52/lauramariel/pomodoro.py index 40cf40c11..56beb78ef 100644 --- a/52/lauramariel/pomodoro.py +++ b/52/lauramariel/pomodoro.py @@ -9,9 +9,6 @@ def timer(timer_type): endtime = datetime.now() + timedelta(minutes=5) elif timer_type == "long_break": endtime = datetime.now() + timedelta(minutes=10) - else: - endtime = "" - print(f"Error") while (datetime.now().replace(microsecond=0) != endtime.replace(microsecond=0)): timeleft = endtime - datetime.now()