-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschedule_manager.py
More file actions
34 lines (27 loc) · 936 Bytes
/
schedule_manager.py
File metadata and controls
34 lines (27 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import os
SCHEDULE_FILE = "schedule.json"
def load_schedule():
"""Loads the schedule from a file."""
if os.path.exists(SCHEDULE_FILE):
with open(SCHEDULE_FILE, "r") as file:
return json.load(file)
return {}
def save_schedule(schedule):
"""Saves the schedule to a file."""
with open(SCHEDULE_FILE, "w") as file:
json.dump(schedule, file, indent=4)
def add_schedule(event, time):
"""Adds an event to the schedule."""
schedule = load_schedule()
schedule[time] = event
save_schedule(schedule)
return f"Event '{event}' added at {time}"
def view_schedule():
"""Displays the schedule."""
schedule = load_schedule()
if not schedule:
return "Your schedule is empty."
return "\n".join([f"{time}: {event}" for time, event in schedule.items()])
if __name__ == "__main__":
print(view_schedule())