From 86cbf3739a077dc93838839071adeb982cc7931d Mon Sep 17 00:00:00 2001 From: Luca Fabbri Date: Wed, 10 Apr 2024 13:15:13 +0200 Subject: [PATCH] Do not create link to event if taken from linked calendar --- HISTORY.rst | 3 ++- haunts/download.py | 9 +++++---- haunts/spreadsheet.py | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index a8a51fa..b93775f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,7 +4,8 @@ History 0.7.1 (unreleased) ------------------ -- report event selection: if user is in invited list, add the event only if she/he accepted or not answered +- read event selection: if user is in invited list, add the event only if she/he accepted or not answered +- read events: do not put event id (I action flag) when event cames from a linked calendar 0.7.0 (2024-04-09) diff --git a/haunts/download.py b/haunts/download.py index 3771eec..41277fc 100644 --- a/haunts/download.py +++ b/haunts/download.py @@ -89,14 +89,15 @@ def extract_events(config_dir, sheet, day): all_events.extend(new_events) # Get calendar configurations - calendar_names = get_calendars_names(sheet_service) + calendar_names = get_calendars_names(sheet_service, flat=False) # Main operation loop for event in all_events: event_summary = event.get("summary", "No summary") start = event["start"].get("dateTime", event["start"].get("date")) end = event["end"].get("dateTime", event["end"].get("date")) - project = calendar_names[event["calendar_id"]] + project = calendar_names[event["calendar_id"]]["alias"] + is_linked = calendar_names[event["calendar_id"]]["is_linked"] start_date = datetime.fromisoformat(start).date() start_time = datetime.fromisoformat(start).time() @@ -111,7 +112,7 @@ def extract_events(config_dir, sheet, day): project_col=project, activity_col=event_summary, details_col=event.get("description", ""), - event_id_col=event["id"], + event_id_col=event["id"] if not is_linked else "", link_col=event.get("htmlLink", ""), - action_col="I", + action_col="I" if not is_linked else "", ) diff --git a/haunts/spreadsheet.py b/haunts/spreadsheet.py index 600b07d..12544f2 100644 --- a/haunts/spreadsheet.py +++ b/haunts/spreadsheet.py @@ -263,10 +263,10 @@ def get_calendars(sheet, ignore_alias=False, use_read_col=False): return configured_calendars -def get_calendars_names(sheet): +def get_calendars_names(sheet, flat=True): """Get all calendars names, giving precedence to alias defined in column "linked_calendar". - If aliases are found, the first one will be used + If multiple aliases are found, the first one will be used """ RANGE = f"{get('CONTROLLER_SHEET_NAME', 'config')}!A2:C" calendars = ( @@ -285,7 +285,9 @@ def get_calendars_names(sheet): linked_id = None if names.get(linked_id) or (names.get(id) and not linked_id): continue - names[linked_id or id] = alias + names[linked_id or id] = ( + alias if flat else {"alias": alias, "is_linked": bool(linked_id)} + ) return names