diff --git a/src/main.py b/src/main.py index ab9c57e..0fde8ef 100644 --- a/src/main.py +++ b/src/main.py @@ -14,27 +14,49 @@ from twapi import TwAPI PROGRAM_ARGS = None -MODES_HELP_STR = '''mode to run the bot at: +MODES_HELP_STR = """mode to run the bot at: scrape accounts in lists and post cross-company tweets if relevant -cmd drop into Python interpretor with access to initialized variables''' +cmd drop into Python interpretor with access to initialized variables""" + def init_argparse(): - p = argparse.ArgumentParser(description='Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.', formatter_class=RawTextHelpFormatter) - p.add_argument('mode', nargs='?', help=MODES_HELP_STR) - p.add_argument('--no-listen', action='store_true', help='Run one scraping-posting cycle without waiting to run again.') - p.add_argument('--refresh-queue', action='store_true', help='Refresh the details on each tweet currently in queue.') - p.add_argument('--straight-to-queue', action='store_true', help='Go through queue first before attempting to pull tweets.') - p.add_argument('--post-id', action='append', help='ID of a tweet to try and post right away. Specify multiple to post multiple tweets in a row.') + p = argparse.ArgumentParser( + description="Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.", + formatter_class=RawTextHelpFormatter, + ) + p.add_argument("mode", nargs="?", help=MODES_HELP_STR) + p.add_argument( + "--no-listen", + action="store_true", + help="Run one scraping-posting cycle without waiting to run again.", + ) + p.add_argument( + "--refresh-queue", + action="store_true", + help="Refresh the details on each tweet currently in queue.", + ) + p.add_argument( + "--straight-to-queue", + action="store_true", + help="Go through queue first before attempting to pull tweets.", + ) + p.add_argument( + "--post-id", + action="append", + help="ID of a tweet to try and post right away. Specify multiple to post multiple tweets in a row.", + ) return p + def command_line(): # TODO (extra): implement command line mode for manually controlling the bot - print('Here\'s a Python interpretor.') + print("Here's a Python interpreter.") try: code.interact(local=globals()) except SystemExit: pass + async def async_main(): global PROGRAM_ARGS @@ -44,12 +66,13 @@ async def async_main(): else: listen.run(PROGRAM_ARGS) return - + mode = PROGRAM_ARGS.mode.lower() - if mode == 'cmd': + if mode == "cmd": command_line() else: - print('\nunknown mode. run with no arguments or -h for help and modes') + print("\nunknown mode. run with no arguments or -h for help and modes") + def init_data(): # Initialize shared API instance @@ -60,12 +83,13 @@ def init_data(): if PROGRAM_ARGS.mode: mode = PROGRAM_ARGS.mode.lower() - if mode != 'cmd': + if mode != "cmd": # Initialize queue files system ttq.TalentTweetQueue() else: ttq.TalentTweetQueue() + def main(): global PROGRAM_ARGS @@ -81,7 +105,7 @@ def main(): ## Asynchronous execution nest_asyncio.apply() asyncio.run(async_main()) - + if __name__ == "__main__": main()