-
Notifications
You must be signed in to change notification settings - Fork 2.2k
day 3 challenge #782
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
day 3 challenge #782
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,46 @@ | ||
| import time | ||
| from datetime import datetime | ||
| from datetime import timedelta | ||
|
|
||
| def timer(timer_type): | ||
| if timer_type == "pomodoro": | ||
|
Collaborator
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. the only difference here are the number of minutes, so you could turn this into a dictionary: |
||
| 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) | ||
|
|
||
| while (datetime.now().replace(microsecond=0) != endtime.replace(microsecond=0)): | ||
| timeleft = endtime - datetime.now() | ||
| timeleft = str(timeleft).split(".")[0] | ||
|
Collaborator
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. Or: |
||
| print(f"{timeleft}", end='\r') | ||
|
Collaborator
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. Is |
||
| time.sleep(1) | ||
|
|
||
| print(f"{timer_type} done!") | ||
| return True | ||
|
|
||
| def main(): | ||
| pomodoro_count = 0 | ||
| while True: | ||
|
Collaborator
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. Is there anything that would break out of this loop? |
||
| 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() | ||
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.
Can do in one import:
from datetime import datetime, timedelta