This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Initial commit

  • Loading branch information...
ErikBjare committed Dec 29, 2014
0 parents commit 689440200bd51f7ee7c0e4e7ef63bc2b8fc53c3f
Showing with 169 additions and 0 deletions.
  1. +58 −0 README.md
  2. +3 −0 create_virtualenv.sh
  3. +7 −0 install_dependencies.sh
  4. +101 −0 watch_window.py
@@ -0,0 +1,58 @@
# Open Computer Time
*A complete RescueTime replacement, for the open world with Zenobase.*
Logs the time spent by the user in different tasks on the computer.
Should log the system and how/when the user uses it.
Then upload to Zenobase or export to JSON (in Zerobase format).
## What it does
Logs every activity on a computer. Page title, name of executable should be included.
Dump all to CSV or upload to Zenobase.
### Why this is important
We think we need logs on our lives, so that we know what we said, did and how much time we spent doing it. Not just so we know, but so that we can improve upon it.
## Output datastructure
Each item has the following data
- Page title
- Path of executable (including name of executable) with timestamp as well as label if idle/afk.
- Optional metadata
- App Store URL (For Android and iOS)
- Package identifier (Android)
Should also perhaps also contain the following metadata
- Date of first and last entry
- Operating system
- Device name (especially if mobile)
- Date of export
- User
### Filters
- Filters could be adding labels by some form of clustering
- It should be possible to filters away all idle/afk entries before export (or not create them to begin with)
- Zenobase viewer buckets could be used
### Software design
- Should support different OS's (Linux, Windows, Android), do this by the strategy pattern for (get (page title and name of executable)).
- Remember to separate the raw exported data from the viewport
## Stories
### Must have
- Log activity
- Label AFK/away time
### Nice to have
- Controller support
- Log tmux activity (Use `tmux server-info` and others to get data)
- Log console commands
## Name propositions
- Activity Watcher (small, it could do more than that)
- System Logger (lacks the focus on activity monitoring)
- Computer Time (taken by [these guys](http://www.softwaretime.com/computertime/))
@@ -0,0 +1,3 @@
#!/bin/bash
sudo pip3 install virtualenv
python3 -m virtualenv virtualenv
@@ -0,0 +1,7 @@
#!/bin/bash
# TODO: Replace with requirements.txt or something
. ./virtualenv/bin/activate
pip3 install psutil --upgrade
pip3 install git+https://github.com/LiuLang/python3-xlib.git --upgrade
deactivate
@@ -0,0 +1,101 @@
#!/usr/bin/python3
#####################
# Stdlib Packages #
#####################
import os
import sys
import subprocess
import unittest
import logging
import time
from time import sleep
from datetime import datetime
#####################
# External packages #
#####################
import psutil
import Xlib
import Xlib.display
from Xlib import X, Xatom
display = Xlib.display.Display()
screen = display.screen()
def main():
window_id = None
selected_at = datetime.now()
while True:
sleep(1.0)
atom = display.get_atom("_NET_ACTIVE_WINDOW")
property = screen.root.get_full_property(atom, X.AnyPropertyType)
# Skip if same as before
if window_id == property.value[0]:
continue
# New window has been focused
# Add actions such as log to local db here
print("Window selected for: {}\n".format(datetime.now() - selected_at))
selected_at = datetime.now()
window_id = property.value[0]
window = get_window(window_id)
property = window.get_full_property(display.get_atom("_NET_WM_PID"), X.AnyPropertyType)
pid = property.value[-1]
proc = process_by_pid(pid)
name, cls = get_window_name(window)
print("Switched to '{}' with PID: {}".format(cls[1], pid))
print("\t{}".format(proc.cmdline()))
def get_window_name(window):
name = None
while window:
cls = window.get_wm_class()
name = window.get_wm_name()
if not cls:
window = window.query_tree().parent
else:
break
return name, cls
def get_window(window_id):
return display.create_resource_object('window', window_id)
def process_by_pid(pid):
p = psutil.Process(int(pid))
logging.debug("Got process: " + str(p.cmdline()))
return p
class Tests(unittest.TestCase):
def test_self(self):
process = process_by_pid(os.getpid())
print(process)
def test_xlib(self):
pass
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
if len(sys.argv) > 1:
cmd = sys.argv[1]
del sys.argv[1]
if cmd == "test":
unittest.main()
elif cmd == "":
pass
else:
print("Unknown command '{}'".format(cmd))
else:
main()

0 comments on commit 6894402

Please sign in to comment.