From 952c47f2ea5007e6ec15c1207200beb7163350a0 Mon Sep 17 00:00:00 2001 From: dotnet Date: Fri, 13 Oct 2023 18:33:23 -0400 Subject: [PATCH] Don't update timestamp if post failed. --- gelbooru_poster.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gelbooru_poster.py b/gelbooru_poster.py index 6ef0814..8d3c121 100644 --- a/gelbooru_poster.py +++ b/gelbooru_poster.py @@ -228,14 +228,18 @@ class BotInstance: def bot_process(self, log_file): # Get a random image making sure it's not in the saved image list + attempts = 10 while True: + if attempts <= 0: + return False image_url, image_src, image_rating, cur_page_number = self.get_random_image(max_page_number=self.max_page_number) self.max_page_number = cur_page_number if image_url is None: + attempts -= 1 continue break # Download and post the image to Misskey - self.post_image(image_url, image_src, image_rating, log_file) + return self.post_image(image_url, image_src, image_rating, log_file) def generate_config(defaults): if os.path.exists("config.json"): @@ -318,7 +322,11 @@ def main(): try: bot_instance = BotInstance(cfg_name, cfg_tmp, log_file) - bot_instance.bot_process(log_file) + if not bot_instance.bot_process(log_file): + print("\n" + cfg_name + ": Error: ", file=log_file) + print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), file=log_file) + print("Error running bot", file=log_file) + continue # Save the saved image list to config.json config[cfg_name]["max_page_number"] = bot_instance.max_page_number # Save the last run time