From 114de79efad436d13d820d1297078df1419a3b9f Mon Sep 17 00:00:00 2001 From: muskit <15199219+muskit@users.noreply.github.com> Date: Tue, 16 May 2023 18:57:07 -0700 Subject: [PATCH] WIP restructuring --- src/catchup.py | 7 ++----- src/main.py | 48 +++++++++------------------------------------ src/talent_lists.py | 2 +- 3 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/catchup.py b/src/catchup.py index b258ca7..759cf22 100644 --- a/src/catchup.py +++ b/src/catchup.py @@ -18,7 +18,7 @@ import talenttweet as tt import ttweetqueue as ttq PROGRAM_ARGS = None -safe_to_post_tweets = True +safe_to_post_tweets = False errored = False ## Returns the ID of all tweets (up to limit) from a user ID. @@ -133,13 +133,10 @@ async def process_queue() -> bool: # return True = no problems # return False = issue occurred where we couldn't post all past tweets properly -async def run(program_args): - global PROGRAM_ARGS +async def run(): global errored global safe_to_post_tweets - PROGRAM_ARGS = program_args - ret = None queue = ttq.TalentTweetQueue.instance while True: await get_cross_talent_tweets() diff --git a/src/main.py b/src/main.py index ea900e2..01eba94 100644 --- a/src/main.py +++ b/src/main.py @@ -24,9 +24,6 @@ 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('--show-tokens', action='store_true', help='[DO NOT USE IN PUBLIC SETTING] print stored tokens from secrets.ini') - p.add_argument('--announce-catchup', action='store_true', help='In catch-up mode, post a tweet announcing catch-up mode.') - p.add_argument('--auto-listen', action='store_true', help='In catch-up mode, transition to listen mode after successfuly catching up.') p.add_argument('--no-delay', action='store_true', help='In self-destruct mode, clear tweets without safety waiting.') return p @@ -45,56 +42,29 @@ async def self_destruct(): async def async_main(): global PROGRAM_ARGS - ## Determine running mode - # match PROGRAM_ARGS.mode.lower(): - # case 'l' | 'listen': - # print('RUNNING IN LISTEN MODE\n') - # await listen.run() - # case 'c' | 'catchup': - # print('RUNNING IN CATCH-UP MODE\n') - # if await catchup.run(PROGRAM_ARGS) and PROGRAM_ARGS.auto_listen: - # print('CATCH-UP MODE DONE, GOING INTO LISTEN MODE') - # await listen.run() - # case 'd' | 'delete-all': - # print('WARNING: SELF-DESTRUCT MODE') - # await self_destruct() - # case 'cmd': - # command_line() - # case _: - # print('\ninvalid mode. run with no arguments or "-h" for help page, including mode list.') - # return + if PROGRAM_ARGS.mode == None: + await catchup.run() + return + mode = PROGRAM_ARGS.mode.lower() - if mode in ['l', 'listen']: - print('RUNNING IN LISTEN MODE') - await listen.run() - elif mode in ['c', 'catchup']: - print('RUNNING IN CATCH UP MODE') - if await catchup.run(PROGRAM_ARGS) and PROGRAM_ARGS.auto_listen: - print('CATCH UP MODE DONE, GOING INTO LISTEN MODE') - listen.run() - elif mode in ['d', 'delete-all']: + if mode in ['d', 'delete-all']: print('WARNING: SELF-DESTRUCT MODE') await self_destruct() elif mode == 'cmd': command_line() else: - print('\ninvalid 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 main(): global PROGRAM_ARGS parser = init_argparse() - if len(sys.argv) < 2: - parser.print_help() - return + # if len(sys.argv) < 2: + # parser.print_help() + # return PROGRAM_ARGS = parser.parse_args() - if PROGRAM_ARGS.show_tokens: - print(api_secrets.get_all_secrets()) - - if PROGRAM_ARGS.mode is None: return - ## We expect to run in some mode now. # Initialize shared API instance diff --git a/src/talent_lists.py b/src/talent_lists.py index 5eb4fbf..f72e4e8 100644 --- a/src/talent_lists.py +++ b/src/talent_lists.py @@ -18,7 +18,7 @@ def __create_dict(file, _dict, company): words = line.split() if len(words) == 2 and line[0] != '#': name, id = line.split() - name = f'{util.get_username_online(id, default=name)}' # attempt to get updated name + # name = f'{util.get_username_online(id, default=name)}' # attempt to get updated name talents[int(id)] = name _dict[int(id)] = name talents_company[int(id)] = company