Redesign post scheduling to have more variation in post time.

This commit is contained in:
dotnet 2023-10-18 19:35:44 -04:00
parent 3aa8d50de3
commit 14ededdf4e
2 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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: