From 760dbd1e07aea7277b1820886d7835dcb9d8e416 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Mon, 19 Aug 2024 10:55:59 +1000 Subject: [PATCH] sheetsync: Convey row parent info by prefixing with a number of ^ characters and noting the parent id in the notes column. --- sheetsync/sheetsync/streamlog.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sheetsync/sheetsync/streamlog.py b/sheetsync/sheetsync/streamlog.py index c757cab..f2a1a44 100644 --- a/sheetsync/sheetsync/streamlog.py +++ b/sheetsync/sheetsync/streamlog.py @@ -126,8 +126,14 @@ class StreamLogEventsMiddleware(Middleware): def get_rows(self): all_rows = [] - for row in self.client.get_entries()["event_log"]: - row = self.parse_row(row) + entries_by_id = {} + for entry in self.client.get_entries()["event_log"]: + # Keep track of how many levels of sub-entry each entry is + entries_by_id[entry["id"]] = entry + parent = entry["parent"] + entry["depth"] = 0 if parent is None else entries_by_id[parent]["depth"] + 1 + + row = self.parse_row(entry) # Malformed rows can be skipped, represented as a None result if row is not None: all_rows.append(row) @@ -157,6 +163,12 @@ class StreamLogEventsMiddleware(Middleware): if output["poster_moment"]: output['tags'] += 'Poster Moment' + # Convey parent info + if row["depth"] > 0: + output["description"] = "^" * row["depth"] + " " + output["description"] + pre_note = f"Part of event {output['parent']}" + output["notes"] = f"{pre_note}. {output['notes']}" if output["notes"] else pre_note + return output def write_value(self, row, key, value):