From 11a46113b59104ffb7408605d21e46cd5df446a0 Mon Sep 17 00:00:00 2001 From: syeopite Date: Sat, 25 Nov 2023 19:19:54 -0800 Subject: [PATCH] Parse post metadata from trail posts --- src/priviblur_extractor/models/timeline.py | 2 ++ src/priviblur_extractor/parsers.py | 20 +++++++++++++++++++- src/templates/macros/post_header.jinja | 11 ++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/priviblur_extractor/models/timeline.py b/src/priviblur_extractor/models/timeline.py index 052009a..850deb7 100644 --- a/src/priviblur_extractor/models/timeline.py +++ b/src/priviblur_extractor/models/timeline.py @@ -30,6 +30,8 @@ class BrokenBlog(NamedTuple): class TimelinePostTrail(NamedTuple): + id: str + date: datetime.datetime blog : Union[TimelineBlog] content: Optional[list[dict]] layout: Optional[list[dict]] diff --git a/src/priviblur_extractor/parsers.py b/src/priviblur_extractor/parsers.py index e998f67..9a0369e 100644 --- a/src/priviblur_extractor/parsers.py +++ b/src/priviblur_extractor/parsers.py @@ -196,10 +196,14 @@ def __parse(target): trails = [] for trail_post in trail: + trail_post_id = None + trail_post_creation_date = None trail_blog = None trail_content = None trail_layout = None + has_error = False + try: if raw_trail_blog := trail_post.get("blog"): trail_blog = _TimelineBlogParser.process(raw_trail_blog, force_parse=True) @@ -208,6 +212,11 @@ def __parse(target): trail_content = trail_post["content"] trail_layout = trail_post["layout"] + + if trail_post_data := trail_post.get("post"): + trail_post_id = trail_post_data["id"] + trail_post_creation_date = datetime.datetime.fromtimestamp(trail_post_data["timestamp"]) + except KeyError as e: logger.warning(f"KeyError: '{e.args[0]}' while parsing post trail for post '{id}' from blog '{blog.name}'") @@ -226,7 +235,16 @@ def __parse(target): if trail_layout is None: trail_layout = [] - trails.append(models.timeline.TimelinePostTrail(trail_blog, trail_content, trail_layout)) + has_error = True + + trails.append(models.timeline.TimelinePostTrail( + trail_post_id, + trail_post_creation_date, + trail_blog, + trail_content, + trail_layout, + has_error + )) # Reblogged from data diff --git a/src/templates/macros/post_header.jinja b/src/templates/macros/post_header.jinja index 7094dbb..4e9bc16 100644 --- a/src/templates/macros/post_header.jinja +++ b/src/templates/macros/post_header.jinja @@ -18,10 +18,15 @@ {{element.blog.name}} {% endif %} - {% if element.date is defined %} + {% if element.date %} - - +