reaching the end of fundamentals!

This commit is contained in:
muskit
2022-09-27 02:49:03 -07:00
committed by msk
parent c06e712e06
commit 07e7e28dcb
6 changed files with 261 additions and 126 deletions
+31 -20
View File
@@ -11,6 +11,8 @@ import catchup
import listen
from twapi import TwAPI
PROGRAM_ARGS = None
MODES_HELP_STR = '''mode to run the bot at:
l,listen: listen for new tweets from all accounts; will not terminate unless error occurs
c,catchup: scan all tweets from all accounts; will terminate when done'''
@@ -20,24 +22,44 @@ def init_argparse():
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.')
return p
# TODO: implement command line mode for manually controlling the bot
def command_line():
# TODO: implement command line mode for manually controlling the bot
pass
async def main():
async def async_main():
global PROGRAM_ARGS
## Determine running mode
match PROGRAM_ARGS.mode.lower():
case 'l' | 'listen':
print('RUNNING IN LISTEN MODE\n')
listen.run()
case 'c' | 'catchup':
print('RUNNING IN CATCH-UP MODE\n')
await catchup.run(PROGRAM_ARGS)
case _:
command_line()
#TODO: remove message
print('\ninvalid mode. run with no arguments or "-h" for help page, including mode list.')
return
def main():
global PROGRAM_ARGS
parser = init_argparse()
if len(sys.argv) < 2:
parser.print_help()
return
args = parser.parse_args()
PROGRAM_ARGS = parser.parse_args()
if args.show_tokens:
if PROGRAM_ARGS.show_tokens:
print(api_secrets.get_all_secrets())
if args.mode is None: return
if PROGRAM_ARGS.mode is None: return
## We expect to run in some mode now.
@@ -47,21 +69,10 @@ async def main():
# Initialize talent account lists
talent_lists.init()
## Determine running mode
match args.mode.lower():
case 'l' | 'listen':
print('RUNNING IN LISTEN MODE\n')
listen.run()
case 'c' | 'catchup':
print('RUNNING IN CATCH-UP MODE\n')
await catchup.run()
case _:
command_line()
#TODO: remove message
print('\ninvalid mode. run with no arguments or "-h" for help page, including mode list.')
return
## Asynchronous execution
nest_asyncio.apply()
asyncio.run(async_main())
if __name__ == "__main__":
nest_asyncio.apply()
asyncio.run(main())
main()