Skip to content

Commit 525edb9

Browse files
committed
add time tracker program
1 parent dda36f6 commit 525edb9

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

TIME_TRACKER/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Break Reminder (Python)
2+
3+
A simple cross-platform Python script that tracks how long your system has been running and reminds you to take a short break every hour.
4+
Works on **Windows, macOS, and Linux** — no external libraries required.
5+
6+
---
7+
8+
## 🚀 Features
9+
- Tracks system uptime in real time
10+
- Sends a **notification every hour** to remind you to rest
11+
- Lightweight and under **100 lines of code**
12+
- Uses only the **Python standard library**
13+
- Works silently in the background (optional)
14+
15+
---
16+
17+
## 🧩 Requirements
18+
- **Python 3.8+**
19+
- Works on:
20+
- Windows 10 / 11
21+
- macOS
22+
- Linux (with `notify-send`)
23+
24+
---
25+
26+
## 💻 Installation
27+
28+
1. Download or copy the file `break_reminder.py`.
29+
2. Make sure Python is installed and added to PATH.
30+
3. Open a terminal or command prompt.
31+
4. Run the script:
32+
33+
```
34+
python break_reminder.py
35+
```
36+
37+
You should see:
38+
39+
```
40+
Break reminder started! You'll get notified every hour.
41+
42+
System on for 0h 5m
43+
```
44+
45+
After an hour of uptime, a notification will appear:
46+
> You’ve been working for an hour! Time to take a short break ☕
47+
48+
---
49+
50+
## ⚙️ Run Silently (Optional)
51+
If you don’t want the console window to stay open:
52+
1. Rename the file to `break_reminder.pyw`.
53+
2. Run it using:
54+
```
55+
pythonw break_reminder.pyw
56+
```
57+
3. Or add it to **Task Scheduler** → “Run at logon” for automatic startup.
58+
59+
---
60+
61+
## 🧠 How It Works
62+
- Retrieves system uptime:
63+
- Windows → `GetTickCount64`
64+
- Linux → `/proc/uptime`
65+
- macOS → `sysctl kern.boottime`
66+
- Every 3600 seconds, displays a platform-specific notification.
67+
- Checks uptime every 30 seconds to avoid heavy resource use.
68+

TIME_TRACKER/time_tracker_app.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""
2+
Break Reminder — A simple cross-platform Python script
3+
that reminds you to take a break every hour based on system uptime.
4+
5+
✅ Works on Windows, macOS, and Linux
6+
✅ Uses only the Python standard library
7+
✅ Under 100 lines and well-commented
8+
"""
9+
10+
import time
11+
import platform
12+
import ctypes
13+
import os
14+
import sys
15+
import datetime
16+
import subprocess
17+
18+
def get_uptime_seconds():
19+
"""Return the system uptime in seconds for the current OS."""
20+
system = platform.system()
21+
22+
try:
23+
if system == "Windows":
24+
# Windows: milliseconds since last boot
25+
return ctypes.windll.kernel32.GetTickCount64() / 1000
26+
27+
elif system == "Linux":
28+
# Linux: read uptime from /proc/uptime
29+
with open("/proc/uptime", "r") as f:
30+
return float(f.readline().split()[0])
31+
32+
elif system == "Darwin":
33+
# macOS: use sysctl to get boot time
34+
boot_time = subprocess.check_output(["sysctl", "-n", "kern.boottime"]).decode()
35+
sec = int(boot_time.split("sec =")[1].split(",")[0])
36+
boot = datetime.datetime.fromtimestamp(sec)
37+
return (datetime.datetime.now() - boot).total_seconds()
38+
39+
else:
40+
raise NotImplementedError("Unsupported OS")
41+
42+
except Exception as e:
43+
print("Error detecting uptime:", e)
44+
return 0
45+
46+
47+
def notify(message):
48+
"""Display a cross-platform notification with the given message."""
49+
system = platform.system()
50+
51+
if system == "Windows":
52+
ctypes.windll.user32.MessageBoxW(0, message, "Break Reminder", 0x40)
53+
elif system == "Darwin":
54+
os.system(f'''osascript -e 'display notification "{message}" with title "Break Reminder"' ''')
55+
else: # Linux
56+
os.system(f'notify-send "Break Reminder" "{message}"')
57+
58+
59+
def main():
60+
"""Main loop — checks uptime and reminds user every hour."""
61+
print("☕ Break Reminder started! You'll be notified every hour.\n")
62+
63+
last_reminder = 0 # Tracks how many hours have passed
64+
65+
while True:
66+
uptime = get_uptime_seconds()
67+
hours_on = int(uptime // 3600)
68+
mins_on = int((uptime % 3600) // 60)
69+
70+
# Show live uptime in the terminal
71+
sys.stdout.write(f"\rSystem on for {hours_on}h {mins_on}m")
72+
sys.stdout.flush()
73+
74+
# Send a reminder every hour
75+
if uptime // 3600 > last_reminder:
76+
notify("You’ve been working for an hour! Time to take a short break ☕")
77+
last_reminder += 1
78+
79+
time.sleep(30) # Check every 30 seconds
80+
81+
82+
if __name__ == "__main__":
83+
main()

0 commit comments

Comments
 (0)