Files
dotfiles/hosts/sctfw004/bin/spanish-time
T
connor e6644d0616 Rebuild dotfiles as one branch with per-host layers
Replaces the previous repo, which had split into two histories that never
met (mainframe on a dead GitLab remote, the laptops on Gitea) with 146
dirty files across three machines and the NAS never enrolled at all.

Branch-per-machine is gone. One main, with host differences expressed as
small files under hosts/<hostname>/ rather than as branches, so there is
nothing to merge. The reconciled zsh layer reduces 15-33 line forks to
1-7 effective lines per host; distro differences (oh-my-zsh prefix,
syntax-highlighting path, fd vs fdfind) are probed in common/ instead.

Fresh history: the old one carried six plaintext credentials, 45 MB of
mail caches, browser caches and vendored binaries. 5,096 tracked files
and 144 MB become 462 files and 2.6 MB. The .gitignore is now an
allowlist, which is what keeps that true.

Root cause of the rot: ~/.local/bin was a symlink to scripts/ with GOPATH
inside it, so every go install wrote into version control (2.2 GB on the
work laptop). PATH now points at the repo instead of the reverse.

Also: Hyprland replaces sway and is sourced in two halves so $browser is
defined before use; singleton automations carry ConditionHost= alongside
host-layer-only placement; ddns moves from cron to a guarded timer;
package manifests and pkg-snapshot/pkg-restore replace the X11-era
install_scripts/; networkmanager-dmenu added to system76 (the binding
always existed, the package never did).
2026-09-14 14:24:37 -04:00

81 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""Total time tagged language:spanish in Traggo, as decimal hours."""
import json
import subprocess
import sys
import urllib.request
from collections import defaultdict
from datetime import datetime, timezone
URL = "https://time.rcjohnstone.com/graphql"
USER = "connor"
def gql(query, cookie=None):
req = urllib.request.Request(
URL,
data=json.dumps({"query": query}).encode(),
headers={"Content-Type": "application/json"},
)
if cookie:
req.add_header("Cookie", f"traggo={cookie}")
body = json.load(urllib.request.urlopen(req))
if body.get("errors"):
sys.exit(f"traggo: {body['errors'][0]['message']}")
return body["data"]
def login():
pw = subprocess.run(
["rbw", "get", "Traggo"], capture_output=True, text=True, check=True
).stdout.strip()
data = gql(
'mutation{login(username:"%s",pass:%s,deviceName:"spanish-time",'
"type:LongExpiry,cookie:false){token}}" % (USER, json.dumps(pw))
)
return data["login"]["token"]
def spans(token):
offset, start_id = 0, None
while True:
cur = f"offset:{offset},pageSize:200"
if start_id is not None:
cur += f",startId:{start_id}"
data = gql(
'{timeSpans(fromInclusive:"2000-01-01T00:00:00Z",'
'toInclusive:"2100-01-01T00:00:00Z",cursor:{%s})'
"{cursor{hasMore offset startId} timeSpans{start end tags{key value}}}}"
% cur,
token,
)["timeSpans"]
yield from data["timeSpans"]
if not data["cursor"]["hasMore"]:
return
offset, start_id = data["cursor"]["offset"], data["cursor"]["startId"]
def main():
by_mode = defaultdict(float)
for span in spans(login()):
tags = {t["key"]: t["value"] for t in span["tags"]}
if tags.get("language") != "spanish":
continue
start = datetime.fromisoformat(span["start"])
end = (
datetime.fromisoformat(span["end"])
if span["end"]
else datetime.now(timezone.utc)
)
by_mode[tags.get("mode", "untagged")] += (end - start).total_seconds() / 3600
if "--by-mode" in sys.argv:
for mode, hours in sorted(by_mode.items(), key=lambda kv: -kv[1]):
print(f"{mode:12s} {hours:8.2f}")
print(f"{sum(by_mode.values()):.2f}")
if __name__ == "__main__":
main()