Skip to content

Commit

Permalink
Pomodoro (#73)
Browse files Browse the repository at this point in the history
* feat : pomodoro timer added

* fix : run_timer function updated

* fix : autopep8

* doc : PROGRAMS.md updated

* doc : CHANGELOG updated

* fix : minor edit in main

* fix : minor edit in pomodoro_timer function

* fix : minor edit in pomodoro_timer function
  • Loading branch information
sepandhaghighi authored Dec 12, 2023
1 parent 2be4d75 commit a355372
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- 1 new program
1. `pomodoro`
### Changed
- `TIME_PRINT_TEMPLATE` changed
- `KeyboardInterrupt` exit handling updated
Expand Down
40 changes: 23 additions & 17 deletions PROGRAMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,105 +12,111 @@
<tr align="center">
<td>Poached egg</td>
<td><code>poached-egg</code></td>
<td>01:30</td>
<td>00:01:30</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Boiled egg</td>
<td><code>boiled-egg</code></td>
<td>03:00</td>
<td>00:03:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Soft-boiled egg</td>
<td><code>soft-boiled-egg</code></td>
<td>05:00</td>
<td>00:05:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Hard-boiled egg</td>
<td><code>hard-boiled-egg</code></td>
<td>10:00</td>
<td>00:10:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Pasta</td>
<td><code>pasta</code></td>
<td>08:00</td>
<td>00:08:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Quick cooking rice</td>
<td><code>quick-rice</code></td>
<td>10:00</td>
<td>00:10:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Japanese green tea</td>
<td><code>japanese-green-tea</code></td>
<td>02:00</td>
<td>00:02:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Tea bag</td>
<td><code>tea-bag</code></td>
<td>02:00</td>
<td>00:02:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Chinese green tea</td>
<td><code>chinese-green-tea</code></td>
<td>05:00</td>
<td>00:05:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Black tea</td>
<td><code>black-tea</code></td>
<td>05:00</td>
<td>00:05:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Oolong tea</td>
<td><code>oolong-tea</code></td>
<td>05:00</td>
<td>00:05:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Fruit tea</td>
<td><code>fruit-tea</code></td>
<td>08:00</td>
<td>00:08:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>White tea</td>
<td><code>white-tea</code></td>
<td>10:00</td>
<td>00:10:00</td>
<td>>=0.6</td>
</tr>
<tr align="center">
<td>Work</td>
<td><code>work</code></td>
<td>25:00</td>
<td>00:25:00</td>
<td>>=0.9</td>
</tr>
<tr align="center">
<td>Short break</td>
<td><code>short-break</code></td>
<td>10:00</td>
<td>00:10:00</td>
<td>>=0.9</td>
</tr>
<tr align="center">
<td>Long break</td>
<td><code>long-break</code></td>
<td>30:00</td>
<td>00:30:00</td>
<td>>=0.9</td>
</tr>
<tr align="center">
<td>Instant noodle</td>
<td><code>noodle</code></td>
<td>03:00</td>
<td>00:03:00</td>
<td>>=0.9</td>
</tr>
<tr align="center">
<td>Pomodoro</td>
<td><code>pomodoro</code></td>
<td>02:40:00</td>
<td>>=1.1</td>
</tr>
</table>


2 changes: 1 addition & 1 deletion mytimer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
args = parser.parse_args()
try:
run_timer(args)
except KeyboardInterrupt:
except (KeyboardInterrupt, EOFError):
print(EXIT_MESSAGE)


Expand Down
37 changes: 37 additions & 0 deletions mytimer/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from mytimer.params import MY_TIMER_VERSION, PROGRAMS_LIST_TEMPLATE
from mytimer.params import FACES_LIST_EXAMPLE_MESSAGE, TIME_PRINT_TEMPLATE
from mytimer.params import DEFAULT_PARAMS, PROGRAMS_DEFAULTS
from mytimer.params import NEXT_PROGRAM_MESSAGE
from art import tprint


Expand Down Expand Up @@ -376,6 +377,37 @@ def countdown_timer(
time.sleep(max(0, 1 - (end - start)))


def pomodoro_timer(timer_func, **params):
"""
Pomodoro timer function.
:param timer_func: timer function
:type timer_func: function
:param params: counter parameters
:type params: dict
:return: None
"""
counter = 0
end_flag = False
break_params = load_program_params("short-break")
break_name = "Short break"
while True:
work_params = params.copy()
work_params["message"] += " {0}/{1}".format(counter + 1, 4)
timer_func(**work_params)
counter += 1
if counter == 4:
break_params = load_program_params("long-break")
break_name = "Long break"
end_flag = True
_ = input(NEXT_PROGRAM_MESSAGE.format(break_name))
timer_func(**break_params)
if end_flag:
break
_ = input(NEXT_PROGRAM_MESSAGE.format(
"Work {0}/{1}".format(counter + 1, 4)))


def run_timer(args):
"""
Run timer.
Expand All @@ -391,6 +423,11 @@ def run_timer(args):
show_faces_list()
elif args.programs_list:
show_programs_list()
elif args.program == "pomodoro":
if args.countdown:
pomodoro_timer(countdown_timer, **params)
else:
pomodoro_timer(countup_timer, **params)
else:
if args.countdown:
countdown_timer(**params)
Expand Down
7 changes: 7 additions & 0 deletions mytimer/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
INPUT_ERROR_MESSAGE = "[Error] Wrong input"
SOUND_ERROR_MESSAGE = "[Error] Unable to play sound"
EXIT_MESSAGE = "See you. Bye!"
NEXT_PROGRAM_MESSAGE = "Press `Enter` to continue (Next: {0})"
PROGRAMS_LIST_TEMPLATE = "{0}. `{1}` - {2}"
TIME_PRINT_TEMPLATE = "{0:02} : {1:02} : {2:02}"
FACES_LIST_EXAMPLE_MESSAGE = "12 : 34 : 56"
Expand Down Expand Up @@ -156,6 +157,12 @@
"second": 0,
"message": "Time to work (25 mins)",
},
"pomodoro": {
"hour": 0,
"minute": 25,
"second": 0,
"message": "Time to work (25 mins)",
},
"short-break": {
"hour": 0,
"minute": 10,
Expand Down

0 comments on commit a355372

Please sign in to comment.