-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdailyreminders.py
More file actions
133 lines (107 loc) · 3.43 KB
/
dailyreminders.py
File metadata and controls
133 lines (107 loc) · 3.43 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import time
import argparse
from datetime import datetime, time as dtime
# -------- DAILY SCHEDULE (EDIT HERE) --------
# 24-hour format
SCHEDULE = [
{
"start": "12:00",
"end": "12:30",
"activity": "Go for a walk 🚶"
},
{
"start": "12:30",
"end": "13:00",
"activity": "Meditate for 10 minutes 🧘"
},
{
"start": "14:00",
"end": "15:00",
"activity": "Study 📚"
}
]
# -------------------------------------------
def print_schedule(schedule):
print("📅 Today's Schedule:\n")
for block in schedule:
print(
f"{block['start'].strftime('%H:%M')} - "
f"{block['end'].strftime('%H:%M')} → "
f"{block['activity']}"
)
print()
def next_block(now_time, schedule):
for block in schedule:
if now_time < block["start"]:
return block
return None
def parse_time(value):
hour, minute = map(int, value.split(":"))
return dtime(hour, minute)
def build_schedule():
parsed = []
for block in SCHEDULE:
parsed.append({
"start": parse_time(block["start"]),
"end": parse_time(block["end"]),
"activity": block["activity"]
})
return parsed
def is_within_block(now, start, end):
return start <= now < end
def run_reminder(interval):
schedule = build_schedule()
print_schedule(schedule)
print("\n⏰ Daily Reminder CLI started")
print("Press CTRL+C to stop\n")
triggered_today = set()
current_date = datetime.now().date()
try:
while True:
now = datetime.now()
now_time = now.time()
# Reset at midnight
if now.date() != current_date:
triggered_today.clear()
current_date = now.date()
for block in schedule:
block_id = (block["start"], block["end"], block["activity"])
if (
is_within_block(now_time, block["start"], block["end"])
and block_id not in triggered_today
):
print(
f"\n🔔 Reminder "
f"({block['start'].strftime('%H:%M')} - "
f"{block['end'].strftime('%H:%M')})"
)
print(f"👉 {block['activity']}\n")
triggered_today.add(block_id)
now_time = datetime.now().time()
upcoming = next_block(now_time, schedule)
if upcoming:
print(
f"⏭️ Next up: "
f"{upcoming['start'].strftime('%H:%M')} - "
f"{upcoming['end'].strftime('%H:%M')} → "
f"{upcoming['activity']}\n"
)
time.sleep(interval)
except KeyboardInterrupt:
print("\n🛑 Reminder service stopped")
# ---------------- CLI ----------------
def parse_args():
parser = argparse.ArgumentParser(
description="⏰ Daily Schedule Reminder CLI"
)
parser.add_argument(
"--interval",
type=int,
default=30,
help="Check interval in seconds (default: 30)"
)
return parser.parse_args()
# ---------------- Entry ----------------
if __name__ == "__main__":
args = parse_args()
run_reminder(args.interval)