format
This commit is contained in:
+38
-14
@@ -14,27 +14,49 @@ from twapi import TwAPI
|
|||||||
|
|
||||||
PROGRAM_ARGS = None
|
PROGRAM_ARGS = None
|
||||||
|
|
||||||
MODES_HELP_STR = '''mode to run the bot at:
|
MODES_HELP_STR = """mode to run the bot at:
|
||||||
<blank> scrape accounts in lists and post cross-company tweets if relevant
|
<blank> 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():
|
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 = argparse.ArgumentParser(
|
||||||
p.add_argument('mode', nargs='?', help=MODES_HELP_STR)
|
description="Twitter bot that follows interactions between Nijisanji EN/ID and hololive EN/ID members.",
|
||||||
p.add_argument('--no-listen', action='store_true', help='Run one scraping-posting cycle without waiting to run again.')
|
formatter_class=RawTextHelpFormatter,
|
||||||
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("mode", nargs="?", help=MODES_HELP_STR)
|
||||||
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.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
|
return p
|
||||||
|
|
||||||
|
|
||||||
def command_line():
|
def command_line():
|
||||||
# TODO (extra): implement command line mode for manually controlling the bot
|
# TODO (extra): implement command line mode for manually controlling the bot
|
||||||
print('Here\'s a Python interpretor.')
|
print("Here's a Python interpreter.")
|
||||||
try:
|
try:
|
||||||
code.interact(local=globals())
|
code.interact(local=globals())
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def async_main():
|
async def async_main():
|
||||||
global PROGRAM_ARGS
|
global PROGRAM_ARGS
|
||||||
|
|
||||||
@@ -44,12 +66,13 @@ async def async_main():
|
|||||||
else:
|
else:
|
||||||
listen.run(PROGRAM_ARGS)
|
listen.run(PROGRAM_ARGS)
|
||||||
return
|
return
|
||||||
|
|
||||||
mode = PROGRAM_ARGS.mode.lower()
|
mode = PROGRAM_ARGS.mode.lower()
|
||||||
if mode == 'cmd':
|
if mode == "cmd":
|
||||||
command_line()
|
command_line()
|
||||||
else:
|
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():
|
def init_data():
|
||||||
# Initialize shared API instance
|
# Initialize shared API instance
|
||||||
@@ -60,12 +83,13 @@ def init_data():
|
|||||||
|
|
||||||
if PROGRAM_ARGS.mode:
|
if PROGRAM_ARGS.mode:
|
||||||
mode = PROGRAM_ARGS.mode.lower()
|
mode = PROGRAM_ARGS.mode.lower()
|
||||||
if mode != 'cmd':
|
if mode != "cmd":
|
||||||
# Initialize queue files system
|
# Initialize queue files system
|
||||||
ttq.TalentTweetQueue()
|
ttq.TalentTweetQueue()
|
||||||
else:
|
else:
|
||||||
ttq.TalentTweetQueue()
|
ttq.TalentTweetQueue()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global PROGRAM_ARGS
|
global PROGRAM_ARGS
|
||||||
|
|
||||||
@@ -81,7 +105,7 @@ def main():
|
|||||||
## Asynchronous execution
|
## Asynchronous execution
|
||||||
nest_asyncio.apply()
|
nest_asyncio.apply()
|
||||||
asyncio.run(async_main())
|
asyncio.run(async_main())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user