Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from datetime import datetime
- import yaml
- def load_tasks(filename):
- with open(filename, 'r') as file:
- tasks = file.readlines()
- return [task.strip() for task in tasks]
- def save_diary(diary, filename):
- today = datetime.now().strftime('%Y-%m-%d')
- try:
- with open(filename, 'r+') as file:
- data = yaml.safe_load(file) or {}
- if today not in data:
- data[today] = {}
- # Move the file pointer to the beginning and write the updated data
- file.seek(0)
- yaml.dump(data, file)
- file.truncate()
- except FileNotFoundError:
- with open(filename, 'w') as file:
- yaml.dump({today: {}}, file)
- def log_click(task, diary):
- today = datetime.now().strftime('%Y-%m-%d')
- current_time = datetime.now().strftime('%Y-%m-%d %H:%M')
- if today not in diary:
- diary[today] = {}
- if task not in diary[today]:
- diary[today][task] = []
- diary[today][task].append(current_time)
- save_diary(diary, 'diary.yaml')
- def load_today_data(filename):
- today = datetime.now().strftime('%Y-%m-%d')
- try:
- with open(filename, 'r') as file:
- data = yaml.safe_load(file) or {}
- return data.get(today, {})
- except FileNotFoundError:
- return {}
- def update_buttons():
- for widget in frame.winfo_children():
- widget.destroy()
- tasks.sort()
- today_clicked = [task for task in tasks if task in diary.get(datetime.now().strftime('%Y-%m-%d'), {})]
- other_tasks = [task for task in tasks if task not in today_clicked]
- all_tasks = sorted(other_tasks) + sorted(today_clicked)
- for task in all_tasks:
- button = tk.Button(frame, text=f"{task} ({diary.get(datetime.now().strftime('%Y-%m-%d'), {}).get(task, 0)})")
- button.config(command=lambda t=task: (log_click(t, diary), update_buttons()))
- button.pack(fill=tk.X)
- if __name__ == '__main__':
- tasks = load_tasks('tasks.txt')
- diary = load_today_data('diary.yaml')
- root = tk.Tk()
- root.title("Daily Routines Diary")
- frame = tk.Frame(root)
- frame.pack(fill=tk.BOTH, expand=True)
- update_buttons()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment