Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions 52/lauramariel/pomodoro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import time
from datetime import datetime
from datetime import timedelta
Copy link
Collaborator

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


def timer(timer_type):
if timer_type == "pomodoro":
Copy link
Collaborator

Choose a reason for hiding this comment

The 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: timer_times = {'pomodoro': 25, 'short_break': 5, 'long_break': 10}, then you don't have to repeat endtime = datetime.now() + timedelta(minutes=<int>) 3 times

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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or:

>>> timeleft
datetime.timedelta(seconds=9, microseconds=687388)
>>> timeleft.seconds
9

print(f"{timeleft}", end='\r')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is \r something you had to do for Windows?

time.sleep(1)

print(f"{timer_type} done!")
return True

def main():
pomodoro_count = 0
while True:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()