Files
Debian-Retzel/Level/Level5/Microsoft.py
2026-01-08 23:32:57 +01:00

41 lines
888 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import time
import pwd
STATE_FILE = "/home/level5/.timer/timer_state.txt"
END_STATE = "/home/level5/.timer/end_state.txt"
def drop_privileges(user):
pw = pwd.getpwnam(user)
os.setgid(pw.pw_gid)
os.setuid(pw.pw_uid)
def countdown(seconds):
if os.path.exists(END_STATE):
os.remove(END_STATE)
for remaining in range(seconds, 0, -1):
with open(STATE_FILE, "w") as f:
f.write(str(remaining))
mins, secs = divmod(remaining, 60)
with open("/home/level5/timer.txt", "w") as f:
f.write(f"{mins:02d}:{secs:02d}")
time.sleep(1)
if os.path.exists(STATE_FILE):
os.remove(STATE_FILE)
with open(END_STATE, "w") as f:
f.write("timeout")
print("Du hast verloren der Timer ist abgelaufen!")
if __name__ == "__main__":
drop_privileges("level5")
countdown(600)