Add --weekly flag to csv command
- Add `write_csv_weekly()` to output.py: writes entries from multiple days as a single CSV with one header row, correct date per row - Add `-w`/`--weekly` flag to csv subparser - _cmd_csv branches on args.weekly: fetches week sections, formats per-day date strings, calls write_csv_weekly; --raw is honoured - Add TestWriteCsvWeekly with 6 tests - Update README with weekly csv usage examples
This commit is contained in:
parent
985ee28113
commit
cd8ca789aa
4 changed files with 134 additions and 10 deletions
|
|
@ -31,6 +31,32 @@ def to_csv_entries(rows: list[dict]) -> list[dict]:
|
|||
]
|
||||
|
||||
|
||||
def write_csv_weekly(
|
||||
day_sections: list[tuple[str, list[dict]]],
|
||||
output: IO[str],
|
||||
project_map: dict,
|
||||
) -> None:
|
||||
"""Write entries from multiple days as a single CSV with one header row.
|
||||
|
||||
day_sections is a list of (date_str, entries) pairs where entries are
|
||||
already write_csv-compatible (project, description, quantity).
|
||||
"""
|
||||
writer = csv.writer(output)
|
||||
writer.writerow(["Date*", "Project*", "Task", "Description", "Quantity"])
|
||||
for date_str, entries in day_sections:
|
||||
for entry in entries:
|
||||
project, task = resolve_project_task(entry["project"], project_map)
|
||||
writer.writerow(
|
||||
[
|
||||
date_str,
|
||||
project,
|
||||
task,
|
||||
entry["description"],
|
||||
f"{entry['quantity']:.2f}",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def write_csv(
|
||||
aggregated: list[dict],
|
||||
output: IO[str],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue