1
0
This commit is contained in:
Jon Michael Aanes 2024-09-21 00:32:19 +02:00
parent 66ba20d629
commit 06dd687a98
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
4 changed files with 26 additions and 16 deletions

View File

@ -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',
)

View File

@ -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)

View File

@ -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 = [
@ -52,7 +53,9 @@ def iterate_samples_from_dicts(rows: list[dict]) -> Iterator[WorkSample]:
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)

View File

@ -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(