Files
NijiHolo_EN_ID_Bot/src/main.py
T

80 lines
2.4 KiB
Python
Raw Normal View History

2022-09-24 17:56:58 -07:00
import sys
import asyncio
2022-09-24 17:56:58 -07:00
import argparse
from argparse import RawTextHelpFormatter
2022-09-27 15:09:09 -07:00
import code
2022-09-24 17:56:58 -07:00
import nest_asyncio
2022-09-24 17:56:58 -07:00
import talent_lists
import ttweetqueue as ttq
2022-09-24 17:56:58 -07:00
import catchup
import listen
2022-09-25 18:31:50 -07:00
from twapi import TwAPI
2022-09-24 17:56:58 -07:00
2022-09-27 02:49:03 -07:00
PROGRAM_ARGS = None
2022-09-24 17:56:58 -07:00
MODES_HELP_STR = '''mode to run the bot at:
2023-08-18 01:34:25 -07:00
<blank> scrape accounts in lists and post cross-company tweets if relevant
cmd drop into Python interpretor with access to initialized variables'''
2022-09-24 17:56:58 -07: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)
2023-08-18 01:34:25 -07:00
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.')
2023-08-18 18:20:53 -07:00
p.add_argument('--refresh-queue', action='store_true', help='Refresh the details on each tweet currently in queue.')
2023-08-18 01:34:25 -07:00
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.')
2022-09-24 17:56:58 -07:00
return p
def command_line():
2022-09-27 22:12:36 -07:00
# TODO (extra): implement command line mode for manually controlling the bot
2023-08-18 01:34:25 -07:00
print('Here\'s a Python interpretor.')
2022-09-27 15:09:09 -07:00
code.interact(local=globals())
2022-09-27 02:49:03 -07:00
async def async_main():
global PROGRAM_ARGS
2023-05-16 18:57:07 -07:00
if PROGRAM_ARGS.mode == None:
2023-08-18 01:34:25 -07:00
if PROGRAM_ARGS.no_listen:
await catchup.run(PROGRAM_ARGS)
else:
listen.run(PROGRAM_ARGS)
2023-05-16 18:57:07 -07:00
return
2022-09-29 07:44:21 +01:00
mode = PROGRAM_ARGS.mode.lower()
2023-08-18 01:34:25 -07:00
if mode == 'cmd':
2022-09-29 07:44:21 +01:00
command_line()
else:
2023-05-16 18:57:07 -07:00
print('\nunknown mode. run with no arguments or -h for help and modes')
2022-09-27 02:49:03 -07:00
2023-08-18 18:20:53 -07:00
def init_data():
# Initialize shared API instance
TwAPI()
# Initialize talent account lists
talent_lists.init()
# Initialize queue files system
ttq.TalentTweetQueue()
2022-09-27 02:49:03 -07:00
def main():
global PROGRAM_ARGS
2022-09-24 17:56:58 -07:00
parser = init_argparse()
2023-08-17 02:28:29 -07:00
if len(sys.argv) < 2:
parser.print_help()
return
2022-09-24 17:56:58 -07:00
2022-09-27 02:49:03 -07:00
PROGRAM_ARGS = parser.parse_args()
2022-09-24 17:56:58 -07:00
2023-08-18 18:20:53 -07:00
init_data()
2022-09-27 02:49:03 -07:00
## Asynchronous execution
nest_asyncio.apply()
asyncio.run(async_main())
2022-09-24 17:56:58 -07:00
if __name__ == "__main__":
2022-09-29 07:44:21 +01:00
main()