forked from kinoshitakenta/auto_login_EIP
97 lines
2.2 KiB
Python
97 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
__author__ = 'kinoshitakenta'
|
|
__email__ = "ybs0306748@gmail.com"
|
|
|
|
import logging
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from utils.cli import cli
|
|
from utils.driver import get_driver
|
|
from utils.EIP_action import ActionType, Action
|
|
from utils.utils import keep_login_status, LoginInfo
|
|
|
|
|
|
def get_usage() -> list[tuple]:
|
|
cmd_list = []
|
|
for e in ActionType:
|
|
cmd_list.append((f"{e.value}", f"{e.name}"))
|
|
|
|
cmd_list.append(("99", "重新輸入登入資訊"))
|
|
cmd_list.append(("exit", "關閉"))
|
|
|
|
return cmd_list
|
|
|
|
|
|
def display_usage():
|
|
if os.name == 'nt':
|
|
os.system('cls')
|
|
else:
|
|
os.system('clear')
|
|
|
|
for cmd, msg in get_usage():
|
|
print(f"{cmd}: {msg}")
|
|
|
|
|
|
def main(opt):
|
|
login_info = LoginInfo(Path(opt.config_path))
|
|
|
|
driver = get_driver()
|
|
keep_login_status(driver, login_info)
|
|
action_agent = Action(driver)
|
|
|
|
display_usage()
|
|
|
|
try:
|
|
while True:
|
|
cmd = input("\nInput action code: ").strip()
|
|
print(f"Retrieve cmd: {cmd}")
|
|
|
|
# * command parse
|
|
if cmd == "exit":
|
|
print("Program is closing...")
|
|
break
|
|
elif cmd == "99":
|
|
login_info = LoginInfo(Path(opt.config_path))
|
|
keep_login_status(driver, login_info)
|
|
continue
|
|
|
|
if not cmd.isdigit():
|
|
print("Input format error, please try again.")
|
|
continue
|
|
else:
|
|
action_code = int(cmd)
|
|
|
|
if not ActionType.has_value(action_code):
|
|
print("Please enter an existing action code.")
|
|
continue
|
|
|
|
# * run command
|
|
keep_login_status(driver, login_info)
|
|
action_agent.run(action_code)
|
|
|
|
except KeyboardInterrupt:
|
|
pass
|
|
|
|
driver.quit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from rich.console import Console
|
|
from rich.traceback import install
|
|
|
|
install(show_locals=True)
|
|
console = Console(tab_size=4, log_path=False)
|
|
|
|
logging.basicConfig(
|
|
filename='log.log',
|
|
filemode='a+',
|
|
level=logging.DEBUG,
|
|
format='%(asctime)s %(levelname)-8s : %(message)s'
|
|
)
|
|
|
|
opt = cli()
|
|
main(opt)
|