diff --git a/git_time_tracker/__init__.py b/git_time_tracker/__init__.py index ac47b11..fbac5ff 100644 --- a/git_time_tracker/__init__.py +++ b/git_time_tracker/__init__.py @@ -39,7 +39,7 @@ from .data import ( WorkSample, ) from .format import cli, icalendar -from .source import git_repo, csv_file +from .source import csv_file, git_repo logger = logging.getLogger(__name__) @@ -51,7 +51,8 @@ MINUTE = datetime.timedelta(minutes=1) def filter_samples( - samples: list[WorkSample], sample_filter: set[str], + samples: list[WorkSample], + sample_filter: set[str], ) -> list[WorkSample]: assert len(sample_filter) > 0 return [s for s in samples if set(s.labels).intersection(sample_filter)] @@ -122,6 +123,7 @@ def parse_arguments(): ) return parser.parse_args() + def load_samples(args): shared_time_stamps_set: set[WorkSample] = set() @@ -141,9 +143,9 @@ def load_samples(args): ) del csv_path - return shared_time_stamps_set + def main(): logging.basicConfig() @@ -173,5 +175,6 @@ def main(): sys.stdout.write(t) elif args.format_mode == 'icalendar': icalendar.generate_icalendar_file( - shared_time_stamps, file='./output/samples.ics', + shared_time_stamps, + file='./output/samples.ics', ) diff --git a/git_time_tracker/format/icalendar.py b/git_time_tracker/format/icalendar.py index ccfab78..d3232b5 100644 --- a/git_time_tracker/format/icalendar.py +++ b/git_time_tracker/format/icalendar.py @@ -9,7 +9,7 @@ HOUR = datetime.timedelta(hours=1) MINUTE = datetime.timedelta(minutes=1) -def create_title(sample: RealizedWorkSample) -> tuple[str,str]: +def create_title(sample: RealizedWorkSample) -> tuple[str, str]: ls = [] desc = [] for label_and_type in sample.labels: @@ -47,7 +47,8 @@ def generate_calendar( for label_and_type in sample.labels: if label_and_type.startswith('author:'): event.add( - 'organizer', 'mailto:' + label_and_type.removeprefix('author:'), + 'organizer', + 'mailto:' + label_and_type.removeprefix('author:'), ) cal.add_component(event) diff --git a/git_time_tracker/source/csv_file.py b/git_time_tracker/source/csv_file.py index 29acb63..657ceea 100644 --- a/git_time_tracker/source/csv_file.py +++ b/git_time_tracker/source/csv_file.py @@ -1,25 +1,26 @@ -import argparse -from collections.abc import Iterator -from decimal import Decimal import datetime import urllib.parse +from collections.abc import Iterator +from decimal import Decimal from pathlib import Path from personal_data.util import load_csv_file from ..data import WorkSample + def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]: max_title_parts = 2 for event_data in rows: - # Select data possible_time_keys = [ k for k, v in event_data.items() if isinstance(v, datetime.date) ] possible_duration_keys = [ - k for k, v in event_data.items() if isinstance(v, Decimal) and 'duration_seconds' in k + k + for k, v in event_data.items() + if isinstance(v, Decimal) and 'duration_seconds' in k ] possible_name_keys = [k for k, v in event_data.items() if isinstance(v, str)] possible_image_keys = [ @@ -31,7 +32,7 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]: if k in possible_misc_keys: possible_misc_keys.remove(k) del k - for k in possible_time_keys : + for k in possible_time_keys: if k in possible_misc_keys: possible_misc_keys.remove(k) del k @@ -45,14 +46,16 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]: if len(possible_duration_keys) > 0: start_at = date seconds = event_data[possible_duration_keys[0]] - end_at = date + datetime.timedelta(seconds = float(seconds)) + end_at = date + datetime.timedelta(seconds=float(seconds)) del seconds else: start_at = None end_at = date title = ': '.join(event_data[k] for k in possible_name_keys[:max_title_parts]) - description = '\n\n'.join(event_data[k] for k in possible_name_keys[max_title_parts:]) + description = '\n\n'.join( + event_data[k] for k in possible_name_keys[max_title_parts:] + ) labels = [f'{k}:{event_data[k]}' for k in possible_misc_keys] @@ -65,6 +68,7 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]: del event_data + def iterate_samples_from_csv_file(file_path: Path) -> Iterator[WorkSample]: dicts = load_csv_file(file_path) yield from iterate_samples_from_dicts(dicts) diff --git a/git_time_tracker/source/git_repo.py b/git_time_tracker/source/git_repo.py index b7e7800..67839aa 100644 --- a/git_time_tracker/source/git_repo.py +++ b/git_time_tracker/source/git_repo.py @@ -39,10 +39,12 @@ def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: labels.append('author:' + commit.author.email) authored_date = datetime.datetime.fromtimestamp( - commit.authored_date, tz=datetime.UTC, + commit.authored_date, + tz=datetime.UTC, ) committed_date = datetime.datetime.fromtimestamp( - commit.committed_date, tz=datetime.UTC, + commit.committed_date, + tz=datetime.UTC, ) yield WorkSample(