2022-09-10 00:47:47 -05:00
import sys
import argparse
from argparse import RawTextHelpFormatter
2022-09-24 04:02:19 -07:00
import talent_lists
2022-09-10 01:21:19 -05:00
import secrets
import catchup
import listen
2022-09-10 00:47:47 -05:00
2022-09-24 04:02:19 -07:00
from api import TwAPI
from util import is_cross_company , print_tweet
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 '''
2022-09-12 01:31:09 -07:00
2022-09-10 00:47:47 -05:00
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 = ' ? ' , \
2022-09-24 04:02:19 -07:00
help = MODES_HELP_STR )
2022-09-10 01:21:19 -05:00
p . add_argument ( ' --show-tokens ' , action = ' store_true ' , help = ' [DO NOT USE IN PUBLIC SETTING] print stored tokens from secrets.ini ' )
2022-09-10 00:47:47 -05:00
return p
2022-09-02 02:09:47 -07:00
def main ( ) :
2022-09-10 00:47:47 -05:00
parser = init_argparse ( )
if len ( sys . argv ) < 2 :
parser . print_help ( )
return
args = parser . parse_args ( )
2022-09-10 01:21:19 -05:00
if args . show_tokens :
print ( secrets . get_all_secrets ( ) )
if args . mode is None : return
2022-09-24 04:02:19 -07:00
## We expect to run in some mode now.
# Initialize shared API instance
twApi = TwAPI . instance = TwAPI ( )
# Initialize talent account lists
talent_lists . init ( )
## TEST CODE ##
cross_pairs = twApi . get_users_cross_tweets_mentions ( 1390620618001838086 )
for pair in cross_pairs :
print_tweet ( pair )
2022-09-12 01:31:09 -07:00
2022-09-24 04:02:19 -07:00
## Determine running mode
2022-09-10 01:21:19 -05:00
match args . mode . lower ( ) :
2022-09-10 00:47:47 -05:00
case ' l ' | ' listen ' :
2022-09-12 01:31:09 -07:00
print ( ' RUNNING IN LISTEN MODE \n ' )
2022-09-10 01:21:19 -05:00
listen . run ( )
2022-09-12 01:31:09 -07:00
case ' c ' | ' catchup ' :
print ( ' RUNNING IN CATCH-UP MODE \n ' )
catchup . run ( )
2022-09-10 01:21:19 -05:00
case _ :
2022-09-20 15:34:38 -07:00
print ( ' \n invalid mode. run with no arguments or " -h " for help page, including mode list. ' )
2022-09-10 01:21:19 -05:00
return
2022-09-10 00:47:47 -05:00
2022-09-02 02:09:47 -07:00
if __name__ == " __main__ " :
main ( )