Readded -o switch

This commit is contained in:
Anon 2022-10-26 20:07:39 -07:00
parent 735e8a8703
commit b18d2ea20e
2 changed files with 13 additions and 8 deletions

View File

@ -20,7 +20,6 @@ import sys
import argparse
import signal
import yandere_bot
import datetime
import contextlib
@ -42,6 +41,7 @@ def main():
parser.add_argument("--debug", help="Same as --dry-run", action="store_true")
parser.add_argument("-c", "--config", help="Set custom config file (Default: {})".format(default_cfg), default=default_cfg)
parser.add_argument("-k", "--keyfile", help="Keyfile used for decryption")
parser.add_argument("-o", "--output", help="Output master list to stdout", action="store_true")
parser.add_argument("remainder", help=argparse.SUPPRESS, nargs=argparse.REMAINDER)
arguments = parser.parse_args()
@ -57,13 +57,21 @@ def main():
raise FailedToLoadCfg("Invalid config file: {}".format(arguments.config))
# Flag if the bot is running in debug mode
debug_mode = arguments.dry_run or arguments.debug
debug_mode = arguments.dry_run or arguments.debug or arguments.output
yandere = yandere_bot.YandereBot(
yandere_config,
arguments.keyfile,
debug_mode
)
# Output master list if -o switch is set
if arguments.output:
with contextlib.redirect_stdout(None):
yandere.prime_bot()
for item in yandere.listPictures:
print(item.get_full_string())
return 0
# Setup exit calls
# Must be done after we declare our bot(s), otherwise this will be called if quitting on decrypting settings )
@ -84,10 +92,10 @@ if __name__ == "__main__":
sys.exit(main())
# Exceptions raised from the main function
except FailedToLoadCfg:
sys.exit(10)
sys.exit(6)
# Exceptions raised from the bot
except yandere_bot.Debug:
sys.exit(6)
sys.exit(5)
except yandere_bot.BadCfgFile:
sys.exit(4)
except yandere_bot.BadPostSettings:

View File

@ -71,14 +71,11 @@ class YandereBot:
# @param cfg A dynamically loaded python module. See yanlib.module_load() for an example
# @param keyfile Keyfile to decrypt settings_post
# @param debug_mode Should the bot run in debug mode (do not sign in or post to Pleroma)
# @prime_bot Should the bot immediately prime itself (configure picture list and login, but don't post)
def __init__(self, cfg, keyfile=None, debug_mode=False, prime_bot=True):
def __init__(self, cfg, keyfile=None, debug_mode=False):
self.cfg = cfg
self.load_settings(self.cfg)
self.debug_mode = debug_mode or self.settings_behavior["debug"]
self.settings_encrypt["keyfile"] = keyfile or self.settings_encrypt["keyfile"]
if prime_bot:
self.prime_bot()
# Setup Exit Calls
def exit(self):