From e66b5fc9680a8595e046197f08e6ae417010241a Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Mon, 23 Dec 2024 09:00:20 +0000 Subject: [PATCH] update webmention script --- bstools/card.py | 25 ++++++++++++------------- bstools/webmention.py | 1 + bstools/wm_state.json | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/bstools/card.py b/bstools/card.py index 608b8af..9cd9e5d 100644 --- a/bstools/card.py +++ b/bstools/card.py @@ -1,4 +1,3 @@ -import uuid import os import hashlib from datetime import datetime @@ -105,27 +104,27 @@ def generate_card(input_file, workspace_path): if os.path.exists(output_path): print(f"{output_path} Already exists, using cached image") - return + else: + print(f"Generating card... {output_path}") + hti.temp_path = Path(workspace_path) / "tmp" - hti.temp_path = Path(workspace_path) / "tmp" + if not os.path.exists(hti.temp_path): + os.mkdir(hti.temp_path) - if not os.path.exists(hti.temp_path): - os.mkdir(hti.temp_path) + files = hti.screenshot( + html_str=[parsed_html], save_as=file_name, size=[(1128, 600)] + ) - files = hti.screenshot( - html_str=[parsed_html], save_as=file_name, size=[(1128, 600)] - ) - - # move from tmp location to workspace folder - output_path = output_path.absolute().as_posix() - os.rename(files[0], output_path) + # move from tmp location to workspace folder + output_path = output_path.absolute().as_posix() + os.rename(files[0], output_path) if "preview" in front_matter: # strip '/social/' from the existing preview value old_fin = front_matter["preview"][:8] old_fill_path = Path(workspace_path) / "static" / "social" / old_fin - if os.path.exists(old_fill_path): + if os.path.exists(old_fill_path) and (old_fill_path != output_path): print(f"Move {old_fill_path} into cleanup...") os.rename(old_fill_path, old_fill_path + ".cleanup") diff --git a/bstools/webmention.py b/bstools/webmention.py index dddff7f..823b1eb 100644 --- a/bstools/webmention.py +++ b/bstools/webmention.py @@ -65,6 +65,7 @@ def update(): feed: feedparser.FeedParserDict = feedparser.parse(os.environ.get("RSS_URL")) + print(f"Checking for new entries on {os.environ.get('RSS_URL')} since {last_updated}") for entry in feed["entries"]: if datetime(*entry["published_parsed"][:6]) > last_updated: links = check_for_links(entry["link"]) diff --git a/bstools/wm_state.json b/bstools/wm_state.json index 4013bd0..1e54b8b 100644 --- a/bstools/wm_state.json +++ b/bstools/wm_state.json @@ -1,13 +1,13 @@ { "last_updated": [ 2024, - 11, - 16, - 17, - 15, - 37, - 5, - 321, + 12, + 22, + 12, + 25, + 46, + 6, + 357, 0 ] } \ No newline at end of file