add task feature

This commit is contained in:
buenosairesam
2025-01-25 07:04:22 -03:00
parent cbb7bf657a
commit 2da2f2641a
14 changed files with 666 additions and 154 deletions

View File

@@ -1,10 +1,10 @@
import subprocess
import os
import datetime
import os
import subprocess
import time
from pprint import pprint
from pymongo import MongoClient
from pprint import pprint
client = MongoClient()
@@ -14,21 +14,49 @@ db = client.deskmeter
switches = db.switch
dailies = db.daily
desktops = ("Work",
"Work",
"Create",
"Other",
"Learn",
"Challenges",
"Idle")
desktops = ("Plan", "Think", "Work", "Other", "Away")
unlabeled = "Idle"
task_file = "/home/mariano/LETRAS/org/task/main"
# desktops = ("Admin",
# "Learn",
# "Tasks",
# "Other",
# "Text",
# "Video",
# "Away")
unlabeled = "Away"
def extract(line):
if line.rstrip().endswith("*"):
pipe_index = line.find("|")
if pipe_index != -1 and len(line) > pipe_index + 8:
value = line[pipe_index + 1 : pipe_index + 9]
return value
return None
def read_and_extract(file_path):
with open(file_path, "r") as file:
for line in file:
value = extract(line)
if value:
return value
return None
def active_workspace():
workspaces = subprocess.check_output(["wmctrl", "-d"]) \
.decode("utf-8").strip("\n").split("\n")
workspaces = (
subprocess.check_output(["wmctrl", "-d"])
.decode("utf-8")
.strip("\n")
.split("\n")
)
for workspace in workspaces:
if workspace[3] == "*":
@@ -41,19 +69,28 @@ def desktop(workspace_index):
except IndexError:
return unlabeled
current_workspace = active_workspace()
current_task = read_and_extract(task_file)
last_switch_time = now()
while True:
if current_workspace != active_workspace():
delta = round((now() - last_switch_time).total_seconds())
# task = ""
# if current_workspace in [0, 1, 2]:
switch = {
"workspace": desktop(current_workspace),
"date": last_switch_time,
"delta": delta,
"task": current_task,
}
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()
current_task = read_and_extract(task_file)
last_switch_time = now()
time.sleep(1)
time.sleep(2)