basic script and web stub
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
__pycache__
|
||||||
|
nohup.out
|
||||||
19
dmapp/dmweb/__init__.py
Normal file
19
dmapp/dmweb/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from flask import Flask
|
||||||
|
from dmweb import dm
|
||||||
|
|
||||||
|
def create_app(test_config=None):
|
||||||
|
|
||||||
|
app = Flask("deskmeter") #instance_relative_config=True
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.makedirs(app.instance_path)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
app.register_blueprint(dm.dmbp)
|
||||||
|
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
7
dmapp/dmweb/dm.py
Normal file
7
dmapp/dmweb/dm.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
dmbp = Blueprint("deskmeter", __name__, url_prefix="/")
|
||||||
|
|
||||||
|
@dmbp.route("/")
|
||||||
|
def index():
|
||||||
|
return "Hello, World!"
|
||||||
6
dmapp/run.py
Normal file
6
dmapp/run.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from dmweb import create_app
|
||||||
|
|
||||||
|
app = create_app()
|
||||||
|
app.run(host='0.0.0.0', debug=True, threaded=True)
|
||||||
|
|
||||||
59
dmmain.py
Normal file
59
dmmain.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
|
from pymongo import MongoClient
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
client = MongoClient()
|
||||||
|
|
||||||
|
now = datetime.datetime.utcnow
|
||||||
|
|
||||||
|
db = client.deskmeter
|
||||||
|
switches = db.switch
|
||||||
|
dailies = db.daily
|
||||||
|
|
||||||
|
desktops = ("Work",
|
||||||
|
"Browse",
|
||||||
|
"Write",
|
||||||
|
"Learn",
|
||||||
|
"Idle")
|
||||||
|
|
||||||
|
|
||||||
|
unlabeled = "Other"
|
||||||
|
|
||||||
|
def active_workspace():
|
||||||
|
|
||||||
|
workspaces = subprocess.check_output(["wmctrl", "-d"]) \
|
||||||
|
.decode("utf-8").strip("\n").split("\n")
|
||||||
|
|
||||||
|
for workspace in workspaces:
|
||||||
|
if workspace[3] == "*":
|
||||||
|
return int(workspace[0])
|
||||||
|
|
||||||
|
|
||||||
|
def desktop(workspace_index):
|
||||||
|
try:
|
||||||
|
return desktops[workspace_index]
|
||||||
|
except IndexError:
|
||||||
|
return unlabeled
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
current_workspace = active_workspace()
|
||||||
|
last_switch_time = now()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if current_workspace != active_workspace():
|
||||||
|
|
||||||
|
delta = round((now() - last_switch_time ).total_seconds())
|
||||||
|
switch = { "workspace": desktop(current_workspace),
|
||||||
|
"date": last_switch_time,
|
||||||
|
"delta": delta }
|
||||||
|
|
||||||
|
switches.insert_one(switch)
|
||||||
|
current_workspace = active_workspace()
|
||||||
|
last_switch_time = now()
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
Reference in New Issue
Block a user