-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmonitortimer.py
More file actions
executable file
·55 lines (45 loc) · 1.26 KB
/
monitortimer.py
File metadata and controls
executable file
·55 lines (45 loc) · 1.26 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
#!/usr/bin/python3
import psutil
import time
from datetime import date
import subprocess
import os
#remove suspicious processes list
susl = [
"sd-pam"
]
# Set the DISPLAY environment variable
os.environ['DISPLAY'] = ':0.0'
soundpath = "/home/nuvhandra/Music/tibet/bowl.wav"
def playsound():
sproc = subprocess.Popen(['cvlc','--play-and-exit', soundpath], close_fds=True)
time.sleep(20)
sproc.kill()
# Set the time limit
today = date.today()
if today.weekday() >= 0 and today.weekday() < 5:
time_limit = 6 * 60 * 60
else:
time_limit = 4 * 60 * 60
print(f"Monitor Timer started, time limit: {(time_limit/60)/60}")
# Main loop to check system usage
while True:
#remove sus
for i in susl:
subprocess.Popen(["killall",i])
# Get the total system uptime in seconds
uptime = psutil.boot_time()
current_time = time.time()
system_usage = current_time - uptime
# Check if the system usage exceeds the time limit
if system_usage > time_limit:
print("Sending notification to user")
# Send a notification
subprocess.Popen(['notify-send', 'Usage Limit Exceeded', 'You have reached the 8-hour usage limit','--expire-time=10000'])
playsound()
time.sleep(60)
print("Poweroff")
subprocess.Popen(['poweroff'])
#break
# Check system usage every 10 minutes
time.sleep(600)