Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from datetime import datetime
- import os
- import pwd
- import subprocess
- import time
- LOG_FILE = os.path.expanduser('~/hours_log.csv')
- cmd = subprocess.Popen(["dbus-monitor \"type='signal',interface="
- "'org.freedesktop.ScreenSaver'\""], shell=True,
- stdout=subprocess.PIPE)
- running = 0
- while 1:
- time.sleep(0.1)
- if running:
- output = cmd.stdout.readline()
- status = 'unlocked' if 'true' in output else 'locked'
- new_line = "{time} {user} {status} the screen\n".format(
- time=datetime.now().ctime(),
- user=pwd.getpwuid(os.getuid())[0],
- status=status
- )
- with open(LOG_FILE, 'a') as f:
- f.write(new_line)
- running = 0
- line = cmd.stdout.readline()
- if "ActiveChange" in line and 'org.freedesktop.ScreenSaver' in line:
- running = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement