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 argparse
import signal import signal
import yandere_bot import yandere_bot
import datetime
import contextlib import contextlib
@ -42,6 +41,7 @@ def main():
parser.add_argument("--debug", help="Same as --dry-run", action="store_true") 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("-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("-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) parser.add_argument("remainder", help=argparse.SUPPRESS, nargs=argparse.REMAINDER)
arguments = parser.parse_args() arguments = parser.parse_args()
@ -57,7 +57,7 @@ def main():
raise FailedToLoadCfg("Invalid config file: {}".format(arguments.config)) raise FailedToLoadCfg("Invalid config file: {}".format(arguments.config))
# Flag if the bot is running in debug mode # 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 = yandere_bot.YandereBot(
yandere_config, yandere_config,
@ -65,6 +65,14 @@ def main():
debug_mode 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 # Setup exit calls
# Must be done after we declare our bot(s), otherwise this will be called if quitting on decrypting settings ) # Must be done after we declare our bot(s), otherwise this will be called if quitting on decrypting settings )
def yandere_quit(signo, _frame): def yandere_quit(signo, _frame):
@ -84,10 +92,10 @@ if __name__ == "__main__":
sys.exit(main()) sys.exit(main())
# Exceptions raised from the main function # Exceptions raised from the main function
except FailedToLoadCfg: except FailedToLoadCfg:
sys.exit(10) sys.exit(6)
# Exceptions raised from the bot # Exceptions raised from the bot
except yandere_bot.Debug: except yandere_bot.Debug:
sys.exit(6) sys.exit(5)
except yandere_bot.BadCfgFile: except yandere_bot.BadCfgFile:
sys.exit(4) sys.exit(4)
except yandere_bot.BadPostSettings: 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 cfg A dynamically loaded python module. See yanlib.module_load() for an example
# @param keyfile Keyfile to decrypt settings_post # @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) # @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):
def __init__(self, cfg, keyfile=None, debug_mode=False, prime_bot=True):
self.cfg = cfg self.cfg = cfg
self.load_settings(self.cfg) self.load_settings(self.cfg)
self.debug_mode = debug_mode or self.settings_behavior["debug"] self.debug_mode = debug_mode or self.settings_behavior["debug"]
self.settings_encrypt["keyfile"] = keyfile or self.settings_encrypt["keyfile"] self.settings_encrypt["keyfile"] = keyfile or self.settings_encrypt["keyfile"]
if prime_bot:
self.prime_bot()
# Setup Exit Calls # Setup Exit Calls
def exit(self): def exit(self):