Redesign post scheduling to have more variation in post time.
This commit is contained in:
parent
3aa8d50de3
commit
14ededdf4e
10
README.md
10
README.md
|
@ -44,7 +44,8 @@ Usage: python3 gelbooru-bot.py [--gen-config] [--help]
|
||||||
"bot_hashtags": "#hololive",
|
"bot_hashtags": "#hololive",
|
||||||
"misskey_token": "uuuu0hOhrrrlrlrP8888uquqaaaaAUAU",
|
"misskey_token": "uuuu0hOhrrrlrlrP8888uquqaaaaAUAU",
|
||||||
"max_page_number": 200,
|
"max_page_number": 200,
|
||||||
"last_run_time": -1
|
"last_run_time": -1,
|
||||||
|
"next_run_time": -1,
|
||||||
},
|
},
|
||||||
"kancolle": {
|
"kancolle": {
|
||||||
"gelbooru_tags": "{kantai_collection ~ boat_girl}",
|
"gelbooru_tags": "{kantai_collection ~ boat_girl}",
|
||||||
|
@ -54,7 +55,8 @@ Usage: python3 gelbooru-bot.py [--gen-config] [--help]
|
||||||
"misskey_token": "HHkkuuuutdtdrrrrvWvW8888yayaaaaa",
|
"misskey_token": "HHkkuuuutdtdrrrrvWvW8888yayaaaaa",
|
||||||
"max_page_number": 200,
|
"max_page_number": 200,
|
||||||
"misskey_url": "https://misskey.io/api/",
|
"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.
|
- `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
|
### defaults.json
|
||||||
|
|
|
@ -263,6 +263,7 @@ def generate_config(defaults):
|
||||||
'misskey_token': defaults['misskey_token'],
|
'misskey_token': defaults['misskey_token'],
|
||||||
'max_page_number': defaults['max_page_number'],
|
'max_page_number': defaults['max_page_number'],
|
||||||
'last_run_time': -1,
|
'last_run_time': -1,
|
||||||
|
'next_run_time': -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
with open("config.json", "w") as config_file:
|
with open("config.json", "w") as config_file:
|
||||||
|
@ -321,10 +322,11 @@ def main():
|
||||||
for key in defaults:
|
for key in defaults:
|
||||||
if key not in cfg_tmp:
|
if key not in cfg_tmp:
|
||||||
cfg_tmp[key] = defaults[key]
|
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
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -338,6 +340,7 @@ def main():
|
||||||
config[cfg_name]["max_page_number"] = bot_instance.max_page_number
|
config[cfg_name]["max_page_number"] = bot_instance.max_page_number
|
||||||
# Save the last run time
|
# Save the last run time
|
||||||
config[cfg_name]["last_run_time"] = time.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
|
# If error, print error and continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue