Add timewarrior config

This commit is contained in:
Maximilian Friedersdorff 2025-08-26 20:38:11 +01:00
parent 940e8f2fea
commit 4518f0efb0
2 changed files with 127 additions and 0 deletions

View file

@ -0,0 +1,87 @@
#!/usr/bin/env python3
from collections import defaultdict
from collections.abc import Iterable
from datetime import datetime, timedelta, timezone, time
import json
import sys
DATE_FORMAT: str = "%Y%m%dT%H%M%SZ"
DATE_OUT_FORMAT: str = "%H:%M"
def fmt_decimal_hours(duration: timedelta) -> float:
return duration.total_seconds() / 3600
def fmt_row(record: dict) -> str:
return "(%3.2f) %5s-%5s %s: %s" % (
fmt_decimal_hours(record["duration"]),
record["start"].strftime(DATE_OUT_FORMAT),
record["end"].strftime(DATE_OUT_FORMAT),
record["project"],
", ".join(record["tags"]),
)
def print_details(records: Iterable[dict]) -> None:
print("{:-^80}".format(" Details "))
print()
for record in records:
print(fmt_row(record))
def print_projects(projects) -> None:
print("{:-^80}".format(" Projects "))
print()
longest = 0
for name in projects.keys():
longest = max(len(name), longest)
for name, project in projects.items():
print(
f"(%3.2f) %{longest + 2}s: %s"
% (fmt_decimal_hours(project["duration"]), name, ", ".join(project["tags"]))
)
for line in sys.stdin:
if line.strip() == "":
break
input = json.load(sys.stdin)
projects = defaultdict(dict)
for record in input:
record["start"] = datetime.strptime(record["start"], DATE_FORMAT)
if "end" in record:
record["end"] = datetime.strptime(record["end"], DATE_FORMAT)
else:
record["end"] = datetime.now()
record["duration"] = record["end"] - record["start"]
record["project"] = ""
for i, tag in enumerate(record["tags"]):
if len(tag) > 0 and tag[0].isupper():
record["project"] = tag
del record["tags"][i]
break
if record["project"] not in projects:
projects[record["project"]] = {
"duration": record["duration"],
"tags": record["tags"],
}
else:
projects[record["project"]]["duration"] += record["duration"]
projects[record["project"]]["tags"] += record["tags"]
print_projects(projects)
print()
print_details(input)

View file

@ -0,0 +1,40 @@
reports.summary.ids = yes
reports.summary.annotations = yes
reports.day.hours = auto
reports.day.spacing = 8
reports.day.lines = 3
reports.week.hours = auto
reports.week.spacing = 8
reports.week.lines = 2
reports.month.hours = auto
define exclusions:
monday = <08:30 >17:30
tuesday = <08:30 >17:30
wednesday = <08:30 >17:30
thursday = <08:30 >17:30
friday = <08:30 >17:30
saturday = >00:00
sunday = >00:00
import /usr/share/doc/timew/themes/dark.theme
theme.colors.label = gray18
define theme:
palette:
color01 = "black on red"
color02 = "black on blue"
color03 = "black on green"
color04 = "black on magenta"
color05 = "black on cyan"
color06 = "black on yellow"
color07 = "black on white"
color08 = "white on bright red"
color09 = "white on bright blue"
color10 = "black on bright green"
color11 = "black on bright magenta"
color12 = "black on bright cyan"
color13 = "black on bright yellow"