Skip to content

Commit

Permalink
Track pomodoro sessions on individual date
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed Mar 6, 2024
1 parent 4b4fbd7 commit 9cb4897
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import json
import customtkinter as ctk
from datetime import datetime
from pygame import mixer


Expand Down Expand Up @@ -145,24 +146,36 @@ def track_second(self):

with open(self.data_file, 'w') as file:
json.dump(data, file, indent=4)

def session_ended(self):
# Reset the timer
self.remaining_time = self.pomodoro_time
minutes, seconds = divmod(self.remaining_time, 60)
self.timer_display.configure(text=f"{minutes:02d}:{seconds:02d}")
self.start_button.configure(text="START")

# Update the total pomodoro sessions done

current_date = datetime.now().strftime("%Y-%m-%d")

# Update the total pomodoro sessions done and sessions done per date
if os.path.exists(self.data_file):
with open(self.data_file, 'r') as file:
data = json.load(file)
data['total_pomodoro_sessions_done'] = data.get('total_pomodoro_sessions_done', 0) + 1

with open(self.data_file, 'w') as file:
json.dump(data, file, indent=4)
if 'sessions_by_date' not in data:
data['sessions_by_date'] = {}
data['sessions_by_date'][current_date] = data['sessions_by_date'].get(current_date, 0) + 1
else:
data = {
'total_seconds_studied': 0,
'total_pomodoro_sessions_done': 1,
'sessions_by_date': {current_date: 1}
}

with open(self.data_file, 'w') as file:
json.dump(data, file, indent=4)

beep.play()
beep.play()


class TabView(ctk.CTkTabview):
Expand Down

0 comments on commit 9cb4897

Please sign in to comment.