From 14ededdf4e5753e3eeae224adb87855775b6b7d6 Mon Sep 17 00:00:00 2001 From: dotnet Date: Wed, 18 Oct 2023 19:35:44 -0400 Subject: [PATCH] Redesign post scheduling to have more variation in post time. --- README.md | 10 +++++++--- gelbooru_poster.py | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 359fd84..d140555 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,8 @@ Usage: python3 gelbooru-bot.py [--gen-config] [--help] "bot_hashtags": "#hololive", "misskey_token": "uuuu0hOhrrrlrlrP8888uquqaaaaAUAU", "max_page_number": 200, - "last_run_time": -1 + "last_run_time": -1, + "next_run_time": -1, }, "kancolle": { "gelbooru_tags": "{kantai_collection ~ boat_girl}", @@ -54,7 +55,8 @@ Usage: python3 gelbooru-bot.py [--gen-config] [--help] "misskey_token": "HHkkuuuutdtdrrrrvWvW8888yayaaaaa", "max_page_number": 200, "misskey_url": "https://misskey.io/api/", - "last_run_time": 1696896202.1551812 + "last_run_time": 1696896202.1551812, + "next_run_time": 1696899802.1551812, } } ``` @@ -69,7 +71,9 @@ Other fields: - `max_page_number:` Automatically determined by the script. -- `last_run_time:` Used to allow the different bots to post at different times by tracking the last time that specific bot posted. +- `last_run_time:` Unused. + +- `next_run_time:` Used to schedule the next time to post on that specific account. ### defaults.json diff --git a/gelbooru_poster.py b/gelbooru_poster.py index e1c2ca7..f0b73cb 100644 --- a/gelbooru_poster.py +++ b/gelbooru_poster.py @@ -263,6 +263,7 @@ def generate_config(defaults): 'misskey_token': defaults['misskey_token'], 'max_page_number': defaults['max_page_number'], 'last_run_time': -1, + 'next_run_time': -1, } with open("config.json", "w") as config_file: @@ -321,10 +322,11 @@ def main(): for key in defaults: if key not in cfg_tmp: cfg_tmp[key] = defaults[key] - if cfg_tmp['last_run_time'] == -1 or cfg_tmp['last_run_time'] > time.time() + 60 * 60: # If last run time is in the future, set it to 1 hour ago - cfg_tmp['last_run_time'] = time.time() - 60 * 60 - if cfg_tmp['last_run_time'] != -1 and time.time() - cfg_tmp['last_run_time'] < 60 * 60: + # Run if current time is greater than the scheduled next run time + if 'next_run_time' not in cfg_tmp: + cfg_tmp['next_run_time'] = -1 + if cfg_tmp['next_run_time'] != -1 and cfg_tmp['next_run_time'] > time.time(): continue try: @@ -338,6 +340,7 @@ def main(): config[cfg_name]["max_page_number"] = bot_instance.max_page_number # Save the last run time config[cfg_name]["last_run_time"] = time.time() + config[cfg_name]['next_run_time'] = time.time() + random.randint(45 * 60, 75 * 60) # If error, print error and continue except Exception as e: