chrome-time-clock 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chrome_time_clock-0.1.0/LICENSE +21 -0
- chrome_time_clock-0.1.0/PKG-INFO +96 -0
- chrome_time_clock-0.1.0/README.md +75 -0
- chrome_time_clock-0.1.0/chrome_time_clock/__init__.py +17 -0
- chrome_time_clock-0.1.0/chrome_time_clock/cli.py +228 -0
- chrome_time_clock-0.1.0/chrome_time_clock/extractor.py +379 -0
- chrome_time_clock-0.1.0/chrome_time_clock/merger.py +147 -0
- chrome_time_clock-0.1.0/chrome_time_clock/plotter.py +377 -0
- chrome_time_clock-0.1.0/chrome_time_clock.egg-info/PKG-INFO +96 -0
- chrome_time_clock-0.1.0/chrome_time_clock.egg-info/SOURCES.txt +14 -0
- chrome_time_clock-0.1.0/chrome_time_clock.egg-info/dependency_links.txt +1 -0
- chrome_time_clock-0.1.0/chrome_time_clock.egg-info/entry_points.txt +5 -0
- chrome_time_clock-0.1.0/chrome_time_clock.egg-info/requires.txt +1 -0
- chrome_time_clock-0.1.0/chrome_time_clock.egg-info/top_level.txt +1 -0
- chrome_time_clock-0.1.0/pyproject.toml +40 -0
- chrome_time_clock-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maurice Frank
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chrome-time-clock
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Infer workday start and end from Chrome, Chromium or Brave history, then plot or merge the hours.
|
|
5
|
+
Author-email: Maurice Frank <maurice.frank@posteo.de>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/morris-frank/chrome-time-clock
|
|
8
|
+
Project-URL: Issues, https://github.com/morris-frank/chrome-time-clock/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
<img src="brand/icon/icon-chrome-time-clock-on-obsidian-1024.png" align="left" width="128" hspace="16" alt="chrome-time-clock icon">
|
|
23
|
+
|
|
24
|
+
<h3>chrome-time-clock</h3>
|
|
25
|
+
|
|
26
|
+
<p>
|
|
27
|
+
<sub>YOUR BROWSER ALREADY KEPT THE TIMESHEET</sub>
|
|
28
|
+
<br>
|
|
29
|
+
<strong>Infer workday start and end from Chrome, Chromium or Brave history, then plot or merge the hours.</strong>
|
|
30
|
+
<br>
|
|
31
|
+
<br>
|
|
32
|
+
<a href="https://pypi.org/project/chrome-time-clock/"><img src="https://img.shields.io/pypi/v/chrome-time-clock?style=flat-square&color=3775A9&logo=pypi&logoColor=white&labelColor=2D2825" alt="PyPI version"></a>
|
|
33
|
+
<img src="https://img.shields.io/badge/python-%E2%89%A53.9-D78A7A?style=flat-square&labelColor=2D2825" alt="Python 3.9+">
|
|
34
|
+
<img src="https://img.shields.io/badge/browsers-Chrome%20%C2%B7%20Chromium%20%C2%B7%20Brave-D78A7A?style=flat-square&labelColor=2D2825" alt="Chrome, Chromium, Brave">
|
|
35
|
+
<img src="https://img.shields.io/badge/OS-macOS%20%C2%B7%20Windows%20%C2%B7%20Linux-7E9688?style=flat-square&labelColor=2D2825" alt="macOS, Windows, Linux">
|
|
36
|
+
<img src="https://img.shields.io/badge/license-MIT-7E9688?style=flat-square&labelColor=2D2825" alt="MIT license">
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<br clear="left">
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
uv tool install chrome-time-clock # or: pipx install chrome-time-clock
|
|
43
|
+
chrome-time-clock extract --out ./export --markdown # history → daily_summary.csv (+ .md)
|
|
44
|
+
chrome-time-clock plot ./export/daily_summary.csv # timeline + histograms, .png and .pdf
|
|
45
|
+
chrome-time-clock merge laptop.csv desktop.csv # union of blocks across machines
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Everything runs locally against a copy of the browser's History SQLite file; nothing leaves the machine.
|
|
49
|
+
|
|
50
|
+
## Extract
|
|
51
|
+
|
|
52
|
+
Groups history visits into active blocks, split wherever the gap exceeds `--gap-minutes`, and reports each day's first and last block.
|
|
53
|
+
|
|
54
|
+
| Option | Default | |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `--browser` | `chrome` | `chrome`, `chromium` or `brave` |
|
|
57
|
+
| `--profile` | `Default` | e.g. `Profile 1` |
|
|
58
|
+
| `--history-db` | — | a History file directly; overrides browser/profile |
|
|
59
|
+
| `--from` / `--to` | — | `YYYY-MM-DD`, inclusive |
|
|
60
|
+
| `--timezone` | `Europe/Amsterdam` | IANA name |
|
|
61
|
+
| `--gap-minutes` | `60` | inactivity that ends a block |
|
|
62
|
+
| `--out` | `./chrome_workhours_export` | CSV output directory |
|
|
63
|
+
| `--markdown` | off | also write `daily_summary.md` |
|
|
64
|
+
|
|
65
|
+
## Plot
|
|
66
|
+
|
|
67
|
+
Dark-theme timeline and start/end histograms from `daily_summary.csv`.
|
|
68
|
+
|
|
69
|
+
| Option | Default | |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `--from` / `--to` | `2026-02-22` / — | `YYYY-MM-DD`, inclusive |
|
|
72
|
+
| `--bins` | `15` | histogram bins |
|
|
73
|
+
| `--out` | `workhours_plot` | file stem; `.png` and `.pdf` appended |
|
|
74
|
+
| `--show` | off | open an interactive window |
|
|
75
|
+
|
|
76
|
+
## Merge
|
|
77
|
+
|
|
78
|
+
Combines several `blocks.csv` files — one per machine or profile — collapsing overlapping intervals:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
chrome-time-clock merge a.csv b.csv --out-blocks merged_blocks.csv --out-daily merged_daily.csv
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Each subcommand also has a standalone shortcut: `chrome-workhours`, `plot-workhours`, `merge-blocks`.
|
|
85
|
+
|
|
86
|
+
## Python API
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from datetime import date
|
|
90
|
+
from chrome_time_clock import extract_workhours, plot_workhours, merge_blocks
|
|
91
|
+
|
|
92
|
+
daily, blocks, warnings = extract_workhours(browser="chrome", profile="Default",
|
|
93
|
+
date_from=date(2026, 6, 1), timezone_str="Europe/Amsterdam")
|
|
94
|
+
plot_workhours(csv_path="./export/daily_summary.csv", date_from=date(2026, 6, 1), out_stem="plot")
|
|
95
|
+
merge_blocks(files=["a.csv", "b.csv"], out_blocks="merged_blocks.csv", out_daily="merged_daily.csv")
|
|
96
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<img src="brand/icon/icon-chrome-time-clock-on-obsidian-1024.png" align="left" width="128" hspace="16" alt="chrome-time-clock icon">
|
|
2
|
+
|
|
3
|
+
<h3>chrome-time-clock</h3>
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<sub>YOUR BROWSER ALREADY KEPT THE TIMESHEET</sub>
|
|
7
|
+
<br>
|
|
8
|
+
<strong>Infer workday start and end from Chrome, Chromium or Brave history, then plot or merge the hours.</strong>
|
|
9
|
+
<br>
|
|
10
|
+
<br>
|
|
11
|
+
<a href="https://pypi.org/project/chrome-time-clock/"><img src="https://img.shields.io/pypi/v/chrome-time-clock?style=flat-square&color=3775A9&logo=pypi&logoColor=white&labelColor=2D2825" alt="PyPI version"></a>
|
|
12
|
+
<img src="https://img.shields.io/badge/python-%E2%89%A53.9-D78A7A?style=flat-square&labelColor=2D2825" alt="Python 3.9+">
|
|
13
|
+
<img src="https://img.shields.io/badge/browsers-Chrome%20%C2%B7%20Chromium%20%C2%B7%20Brave-D78A7A?style=flat-square&labelColor=2D2825" alt="Chrome, Chromium, Brave">
|
|
14
|
+
<img src="https://img.shields.io/badge/OS-macOS%20%C2%B7%20Windows%20%C2%B7%20Linux-7E9688?style=flat-square&labelColor=2D2825" alt="macOS, Windows, Linux">
|
|
15
|
+
<img src="https://img.shields.io/badge/license-MIT-7E9688?style=flat-square&labelColor=2D2825" alt="MIT license">
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
<br clear="left">
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
uv tool install chrome-time-clock # or: pipx install chrome-time-clock
|
|
22
|
+
chrome-time-clock extract --out ./export --markdown # history → daily_summary.csv (+ .md)
|
|
23
|
+
chrome-time-clock plot ./export/daily_summary.csv # timeline + histograms, .png and .pdf
|
|
24
|
+
chrome-time-clock merge laptop.csv desktop.csv # union of blocks across machines
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Everything runs locally against a copy of the browser's History SQLite file; nothing leaves the machine.
|
|
28
|
+
|
|
29
|
+
## Extract
|
|
30
|
+
|
|
31
|
+
Groups history visits into active blocks, split wherever the gap exceeds `--gap-minutes`, and reports each day's first and last block.
|
|
32
|
+
|
|
33
|
+
| Option | Default | |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `--browser` | `chrome` | `chrome`, `chromium` or `brave` |
|
|
36
|
+
| `--profile` | `Default` | e.g. `Profile 1` |
|
|
37
|
+
| `--history-db` | — | a History file directly; overrides browser/profile |
|
|
38
|
+
| `--from` / `--to` | — | `YYYY-MM-DD`, inclusive |
|
|
39
|
+
| `--timezone` | `Europe/Amsterdam` | IANA name |
|
|
40
|
+
| `--gap-minutes` | `60` | inactivity that ends a block |
|
|
41
|
+
| `--out` | `./chrome_workhours_export` | CSV output directory |
|
|
42
|
+
| `--markdown` | off | also write `daily_summary.md` |
|
|
43
|
+
|
|
44
|
+
## Plot
|
|
45
|
+
|
|
46
|
+
Dark-theme timeline and start/end histograms from `daily_summary.csv`.
|
|
47
|
+
|
|
48
|
+
| Option | Default | |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `--from` / `--to` | `2026-02-22` / — | `YYYY-MM-DD`, inclusive |
|
|
51
|
+
| `--bins` | `15` | histogram bins |
|
|
52
|
+
| `--out` | `workhours_plot` | file stem; `.png` and `.pdf` appended |
|
|
53
|
+
| `--show` | off | open an interactive window |
|
|
54
|
+
|
|
55
|
+
## Merge
|
|
56
|
+
|
|
57
|
+
Combines several `blocks.csv` files — one per machine or profile — collapsing overlapping intervals:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
chrome-time-clock merge a.csv b.csv --out-blocks merged_blocks.csv --out-daily merged_daily.csv
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Each subcommand also has a standalone shortcut: `chrome-workhours`, `plot-workhours`, `merge-blocks`.
|
|
64
|
+
|
|
65
|
+
## Python API
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from datetime import date
|
|
69
|
+
from chrome_time_clock import extract_workhours, plot_workhours, merge_blocks
|
|
70
|
+
|
|
71
|
+
daily, blocks, warnings = extract_workhours(browser="chrome", profile="Default",
|
|
72
|
+
date_from=date(2026, 6, 1), timezone_str="Europe/Amsterdam")
|
|
73
|
+
plot_workhours(csv_path="./export/daily_summary.csv", date_from=date(2026, 6, 1), out_stem="plot")
|
|
74
|
+
merge_blocks(files=["a.csv", "b.csv"], out_blocks="merged_blocks.csv", out_daily="merged_daily.csv")
|
|
75
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Chrome Time Clock
|
|
3
|
+
|
|
4
|
+
Infer approximate workday start/end from Chrome browser history and plot/merge work hours.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from chrome_time_clock.extractor import extract_workhours
|
|
8
|
+
from chrome_time_clock.merger import merge_blocks
|
|
9
|
+
from chrome_time_clock.plotter import plot_workhours
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"extract_workhours",
|
|
15
|
+
"plot_workhours",
|
|
16
|
+
"merge_blocks",
|
|
17
|
+
]
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Unified command-line interface for chrome-time-clock."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from chrome_time_clock.extractor import DEFAULT_GAP_MINUTES, DEFAULT_OUT_DIR, DEFAULT_PROFILE, DEFAULT_TIMEZONE, extract_workhours, write_csv, write_markdown
|
|
9
|
+
from chrome_time_clock.merger import merge_blocks
|
|
10
|
+
from chrome_time_clock.plotter import plot_workhours
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
"""Main entry point for the unified chrome-time-clock CLI."""
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="chrome-time-clock",
|
|
17
|
+
description="Chrome Time Clock: Infer, plot, and merge work hours from browser history.",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
subparsers = parser.add_subparsers(dest="command", required=True, title="subcommands")
|
|
21
|
+
|
|
22
|
+
# ── Extract Subcommand ────────────────────────────────────────────────────
|
|
23
|
+
extract_parser = subparsers.add_parser(
|
|
24
|
+
"extract",
|
|
25
|
+
help="Infer workday start/end from browser history",
|
|
26
|
+
description="Infer workday start/end from Chrome/Chromium/Brave browser history.",
|
|
27
|
+
)
|
|
28
|
+
extract_parser.add_argument(
|
|
29
|
+
"--profile",
|
|
30
|
+
default=DEFAULT_PROFILE,
|
|
31
|
+
help=f"Browser profile name (default: {DEFAULT_PROFILE})",
|
|
32
|
+
)
|
|
33
|
+
extract_parser.add_argument(
|
|
34
|
+
"--browser",
|
|
35
|
+
default="chrome",
|
|
36
|
+
choices=["chrome", "chromium", "brave"],
|
|
37
|
+
help="Browser type (default: chrome)",
|
|
38
|
+
)
|
|
39
|
+
extract_parser.add_argument(
|
|
40
|
+
"--history-db",
|
|
41
|
+
default=None,
|
|
42
|
+
help="Direct path to History SQLite file (overrides browser/profile resolution)",
|
|
43
|
+
)
|
|
44
|
+
extract_parser.add_argument(
|
|
45
|
+
"--from",
|
|
46
|
+
dest="date_from",
|
|
47
|
+
default=None,
|
|
48
|
+
help="Start date YYYY-MM-DD (inclusive)",
|
|
49
|
+
)
|
|
50
|
+
extract_parser.add_argument(
|
|
51
|
+
"--to",
|
|
52
|
+
dest="date_to",
|
|
53
|
+
default=None,
|
|
54
|
+
help="End date YYYY-MM-DD (inclusive)",
|
|
55
|
+
)
|
|
56
|
+
extract_parser.add_argument(
|
|
57
|
+
"--timezone",
|
|
58
|
+
default=DEFAULT_TIMEZONE,
|
|
59
|
+
help=f"IANA timezone (default: {DEFAULT_TIMEZONE})",
|
|
60
|
+
)
|
|
61
|
+
extract_parser.add_argument(
|
|
62
|
+
"--gap-minutes",
|
|
63
|
+
type=int,
|
|
64
|
+
default=DEFAULT_GAP_MINUTES,
|
|
65
|
+
help=f"Inactivity gap threshold in minutes (default: {DEFAULT_GAP_MINUTES})",
|
|
66
|
+
)
|
|
67
|
+
extract_parser.add_argument(
|
|
68
|
+
"--out",
|
|
69
|
+
default=DEFAULT_OUT_DIR,
|
|
70
|
+
help=f"Output directory (default: {DEFAULT_OUT_DIR})",
|
|
71
|
+
)
|
|
72
|
+
extract_parser.add_argument(
|
|
73
|
+
"--markdown",
|
|
74
|
+
action="store_true",
|
|
75
|
+
help="Also write daily_summary.md inside the output directory",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# ── Plot Subcommand ───────────────────────────────────────────────────────
|
|
79
|
+
plot_parser = subparsers.add_parser(
|
|
80
|
+
"plot",
|
|
81
|
+
help="Work-hour timelines and histograms",
|
|
82
|
+
description="Generate work-hour timelines and histograms in dark Soilytix style.",
|
|
83
|
+
)
|
|
84
|
+
plot_parser.add_argument(
|
|
85
|
+
"csv",
|
|
86
|
+
help="Path to the daily summary CSV file",
|
|
87
|
+
)
|
|
88
|
+
plot_parser.add_argument(
|
|
89
|
+
"--from",
|
|
90
|
+
dest="date_from",
|
|
91
|
+
default="2026-02-22",
|
|
92
|
+
help="Start date YYYY-MM-DD (inclusive) (default: 2026-02-22)",
|
|
93
|
+
)
|
|
94
|
+
plot_parser.add_argument(
|
|
95
|
+
"--to",
|
|
96
|
+
dest="date_to",
|
|
97
|
+
default=None,
|
|
98
|
+
help="End date YYYY-MM-DD (inclusive)",
|
|
99
|
+
)
|
|
100
|
+
plot_parser.add_argument(
|
|
101
|
+
"--bins",
|
|
102
|
+
type=int,
|
|
103
|
+
default=15,
|
|
104
|
+
help="Number of bins for histograms (default: 15)",
|
|
105
|
+
)
|
|
106
|
+
plot_parser.add_argument(
|
|
107
|
+
"--out",
|
|
108
|
+
default="workhours_plot",
|
|
109
|
+
help="Output file stem — .png and .pdf are appended (default: workhours_plot)",
|
|
110
|
+
)
|
|
111
|
+
plot_parser.add_argument(
|
|
112
|
+
"--show",
|
|
113
|
+
action="store_true",
|
|
114
|
+
help="Display the plot window",
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# ── Merge Subcommand ──────────────────────────────────────────────────────
|
|
118
|
+
merge_parser = subparsers.add_parser(
|
|
119
|
+
"merge",
|
|
120
|
+
help="Merge blocks.csv files",
|
|
121
|
+
description="Merge multiple blocks.csv files, collapsing overlapping time intervals.",
|
|
122
|
+
)
|
|
123
|
+
merge_parser.add_argument(
|
|
124
|
+
"files",
|
|
125
|
+
nargs="+",
|
|
126
|
+
help="List of blocks.csv files to merge",
|
|
127
|
+
)
|
|
128
|
+
merge_parser.add_argument(
|
|
129
|
+
"--out-blocks",
|
|
130
|
+
default="merged_blocks.csv",
|
|
131
|
+
help="Output filename for merged blocks (default: merged_blocks.csv)",
|
|
132
|
+
)
|
|
133
|
+
merge_parser.add_argument(
|
|
134
|
+
"--out-daily",
|
|
135
|
+
default="merged_daily.csv",
|
|
136
|
+
help="Output filename for derived daily summary (default: merged_daily.csv)",
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Parse arguments
|
|
140
|
+
args = parser.parse_args()
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
if args.command == "extract":
|
|
144
|
+
date_from = (
|
|
145
|
+
datetime.strptime(args.date_from, "%Y-%m-%d").date() if args.date_from else None
|
|
146
|
+
)
|
|
147
|
+
date_to = (
|
|
148
|
+
datetime.strptime(args.date_to, "%Y-%m-%d").date() if args.date_to else None
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
daily_rows, block_rows, warnings = extract_workhours(
|
|
152
|
+
browser=args.browser,
|
|
153
|
+
profile=args.profile,
|
|
154
|
+
history_db=args.history_db,
|
|
155
|
+
date_from=date_from,
|
|
156
|
+
date_to=date_to,
|
|
157
|
+
timezone_str=args.timezone,
|
|
158
|
+
gap_minutes=args.gap_minutes,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
if not daily_rows:
|
|
162
|
+
print("No visits found after filtering. Nothing to do.")
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
print(f"Days summarised: {len(daily_rows)}")
|
|
166
|
+
for w in warnings:
|
|
167
|
+
print(f" {w}")
|
|
168
|
+
|
|
169
|
+
out_dir = Path(args.out)
|
|
170
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
171
|
+
|
|
172
|
+
daily_path = out_dir / "daily_summary.csv"
|
|
173
|
+
blocks_path = out_dir / "blocks.csv"
|
|
174
|
+
|
|
175
|
+
write_csv(
|
|
176
|
+
daily_rows,
|
|
177
|
+
daily_path,
|
|
178
|
+
["date", "first_seen", "last_seen", "gross_span_hours", "active_block_hours", "n_blocks", "n_visits"],
|
|
179
|
+
)
|
|
180
|
+
write_csv(
|
|
181
|
+
block_rows,
|
|
182
|
+
blocks_path,
|
|
183
|
+
["date", "block_start", "block_end", "duration_hours", "n_visits"],
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
if args.markdown:
|
|
187
|
+
md_path = out_dir / "daily_summary.md"
|
|
188
|
+
write_markdown(daily_rows, md_path)
|
|
189
|
+
print(f"Markdown written to: {md_path}")
|
|
190
|
+
|
|
191
|
+
print(f"Output written to: {out_dir.resolve()}")
|
|
192
|
+
print(f" {daily_path.name}: {len(daily_rows)} days")
|
|
193
|
+
print(f" {blocks_path.name}: {len(block_rows)} blocks")
|
|
194
|
+
|
|
195
|
+
elif args.command == "plot":
|
|
196
|
+
date_from = (
|
|
197
|
+
datetime.strptime(args.date_from, "%Y-%m-%d").date() if args.date_from else None
|
|
198
|
+
)
|
|
199
|
+
date_to = (
|
|
200
|
+
datetime.strptime(args.date_to, "%Y-%m-%d").date() if args.date_to else None
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
plot_workhours(
|
|
204
|
+
csv_path=args.csv,
|
|
205
|
+
date_from=date_from,
|
|
206
|
+
date_to=date_to,
|
|
207
|
+
bins=args.bins,
|
|
208
|
+
out_stem=args.out,
|
|
209
|
+
show=args.show,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
elif args.command == "merge":
|
|
213
|
+
merge_blocks(
|
|
214
|
+
files=args.files,
|
|
215
|
+
out_blocks=args.out_blocks,
|
|
216
|
+
out_daily=args.out_daily,
|
|
217
|
+
)
|
|
218
|
+
print(f"Successfully merged {len(args.files)} file(s).")
|
|
219
|
+
print(f"Written: {args.out_blocks}")
|
|
220
|
+
print(f"Written: {args.out_daily}")
|
|
221
|
+
|
|
222
|
+
except Exception as e:
|
|
223
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
224
|
+
sys.exit(1)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if __name__ == "__main__":
|
|
228
|
+
main()
|