From 41d893a1380af5d4531345359ec85518f4b1584c Mon Sep 17 00:00:00 2001 From: Tafsir Thiam Date: Wed, 14 Apr 2021 22:58:03 -0400 Subject: [PATCH 1/3] PCC52 ttafsir --- 52/ttafsir/pomodoro.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 52/ttafsir/pomodoro.py diff --git a/52/ttafsir/pomodoro.py b/52/ttafsir/pomodoro.py new file mode 100644 index 00000000..37cc631c --- /dev/null +++ b/52/ttafsir/pomodoro.py @@ -0,0 +1,23 @@ +from rich.console import Console +from rich.layout import Layout +from rich.panel import Panel +from rich.live import Live +from time import sleep +from datetime import timedelta + + +console = Console() + + +minutes = 25 +countdown_timer = timedelta(minutes=minutes) + + +console.print(f"\nPOMODORO TIMER: {minutes}:00") +with Live(auto_refresh=False) as live: + while countdown_timer: + console.print(str(countdown_timer), end="\r") + countdown_timer += timedelta(seconds=-1) + sleep(1) + live.refresh() + console.print("TIME IS UP!") From c95332a9eb0ee4854b138df84acc4367f669e98c Mon Sep 17 00:00:00 2001 From: Tafsir Thiam Date: Wed, 14 Apr 2021 23:56:51 -0400 Subject: [PATCH 2/3] refactor to class --- 52/ttafsir/pomodoro.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/52/ttafsir/pomodoro.py b/52/ttafsir/pomodoro.py index 37cc631c..7b80ab6b 100644 --- a/52/ttafsir/pomodoro.py +++ b/52/ttafsir/pomodoro.py @@ -1,6 +1,4 @@ from rich.console import Console -from rich.layout import Layout -from rich.panel import Panel from rich.live import Live from time import sleep from datetime import timedelta @@ -9,15 +7,34 @@ console = Console() -minutes = 25 -countdown_timer = timedelta(minutes=minutes) +class PomodoroTimer: + def __init__(self, start_timer=25, break_timer=5): + self._timer = start_timer + self._break = break_timer + self._countdown = timedelta(minutes=self._timer) -console.print(f"\nPOMODORO TIMER: {minutes}:00") -with Live(auto_refresh=False) as live: - while countdown_timer: - console.print(str(countdown_timer), end="\r") - countdown_timer += timedelta(seconds=-1) - sleep(1) - live.refresh() - console.print("TIME IS UP!") + def run(self, prompt="TIMER"): + with Live(auto_refresh=False) as live: + while self._countdown: + console.print(f"{prompt}: {self._countdown}", end="\r") + self._countdown += timedelta(seconds=-1) + sleep(1) + live.refresh() + + def restart(self, start_timer, prompt): + self._countdown = timedelta(minutes=start_timer) + self.run(prompt) + + +timer_duration = int(input('Duration: ').strip()) +break_duration = int(input('Break Duration: ').strip()) +console.print("\nCTRL+C to quit") +while True: + try: + timer = PomodoroTimer(start_timer=timer_duration) + timer.run() + timer.restart(start_timer=break_duration, prompt="BREAK") + except KeyboardInterrupt: + console.print("TIME'S UP") + break From c600680ef459476c70d34a127776c5caadbfc29d Mon Sep 17 00:00:00 2001 From: Tafsir Thiam Date: Wed, 14 Apr 2021 23:57:51 -0400 Subject: [PATCH 3/3] lint --- 52/ttafsir/pomodoro.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/52/ttafsir/pomodoro.py b/52/ttafsir/pomodoro.py index 7b80ab6b..f1e37474 100644 --- a/52/ttafsir/pomodoro.py +++ b/52/ttafsir/pomodoro.py @@ -8,7 +8,6 @@ class PomodoroTimer: - def __init__(self, start_timer=25, break_timer=5): self._timer = start_timer self._break = break_timer @@ -27,8 +26,8 @@ def restart(self, start_timer, prompt): self.run(prompt) -timer_duration = int(input('Duration: ').strip()) -break_duration = int(input('Break Duration: ').strip()) +timer_duration = int(input("Duration: ").strip()) +break_duration = int(input("Break Duration: ").strip()) console.print("\nCTRL+C to quit") while True: try: