Skip to content

Commit

Permalink
feat(cli): add gui command
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandaft committed Mar 16, 2023
1 parent 5b74fde commit db9f0ae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions esurfingpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .cli import cli
from .esurfing import ESurfing, login, logout
from .gui import Gui
from .log import log
4 changes: 2 additions & 2 deletions esurfingpy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.4.1"
__date__ = "2023/03/14"
__version__ = "0.4.2"
__date__ = "2023/03/16"
__url__ = "https://github.com/Pandaft/ESurfingPy-CLI/"
27 changes: 17 additions & 10 deletions esurfingpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import esurfing
from .__version__ import __version__, __date__
from .auto import relogin
from .gui import Gui
from .ocr import ocr_image

DEFAULT_ESURFING_URL = "enet.10000.gd.cn:10001"
Expand All @@ -17,14 +18,20 @@ def cli():
pass


@cli.command()
@cli.command(name="gui")
def cli_gui():
"""启动图形界面"""
Gui().run()


@cli.command(name="login")
@click.option('-u', '--esurfing-url', default=DEFAULT_ESURFING_URL, show_default=True, help='校园网登录网址')
@click.option('-c', '--wlan-acip', help='认证服务器IP')
@click.option('-r', '--wlan-userip', help='登录设备IP')
@click.option('-a', '--account', prompt='账号', help='账号')
@click.option('-p', '--password', prompt='密码', help='密码')
@click.option('-v', '--verbose', type=bool, default=True, show_default=True, help='输出详细过程')
def login(esurfing_url, wlan_acip, wlan_userip, account, password, verbose):
def cli_login(esurfing_url, wlan_acip, wlan_userip, account, password, verbose):
"""登录校园网"""
# account, password 必填参数;
# esurfing_url, wlan_acip, wlan_userip 选填参数,本机登录且未登录时可自动获取;
Expand All @@ -33,15 +40,15 @@ def login(esurfing_url, wlan_acip, wlan_userip, account, password, verbose):
account=account, password=password, verbose=verbose)


@cli.command()
@cli.command(name="logout")
@click.option('-u', '--esurfing-url', default=DEFAULT_ESURFING_URL, help='校园网登录网址')
@click.option('-c', '--wlan-acip', prompt='认证服务器IP', help='认证服务器IP')
@click.option('-r', '--wlan-userip', prompt='登录设备IP', help='登录设备IP')
@click.option('-a', '--account', prompt='账号', help='账号')
@click.option('-p', '--password', prompt='密码', help='密码')
@click.option('-s', '--signature', help='签名')
@click.option('-v', '--verbose', type=bool, default=True, show_default=True, help='输出详细过程')
def logout(esurfing_url, wlan_acip, wlan_userip, account, password, signature, verbose):
def cli_logout(esurfing_url, wlan_acip, wlan_userip, account, password, signature, verbose):
"""登出校园网"""
# account 必填参数;
# esurfing_url, wlan_acip, wlan_userip 必填参数;
Expand All @@ -51,7 +58,7 @@ def logout(esurfing_url, wlan_acip, wlan_userip, account, password, signature, v
account=account, password=password, signature=signature, verbose=verbose)


@cli.command()
@cli.command(name="auto")
@click.option('-m', '--mode', prompt='触发模式', help='触发模式', type=click.Choice(["uls", "dls", "ult", "dlt", "itv", "mul"], case_sensitive=False))
@click.option('-t', '--threshold', prompt='触发阈值', type=float, help='触发网速(MB/s)或流量(MB)或时间(s)')
@click.option('-s', '--auto-stop', prompt='自动停止', default=True, show_default=True, type=bool, help='自动停止(仅对网速模式有效)')
Expand All @@ -61,7 +68,7 @@ def logout(esurfing_url, wlan_acip, wlan_userip, account, password, signature, v
@click.option('-a', '--account', prompt='账号', help='账号')
@click.option('-p', '--password', prompt='密码', help='密码')
@click.option('-v', '--verbose', type=bool, default=True, show_default=True, help='输出详细过程')
def auto(mode, threshold, auto_stop, esurfing_url, wlan_acip, wlan_userip, account, password, verbose):
def cli_auto(mode, threshold, auto_stop, esurfing_url, wlan_acip, wlan_userip, account, password, verbose):
"""多种模式触发重登校园网"""
# mode:
# uls, upload_speed - 上行速率低于指定值时自动重登校园网
Expand All @@ -82,9 +89,9 @@ def auto(mode, threshold, auto_stop, esurfing_url, wlan_acip, wlan_userip, accou
return relogin(esf, mode, threshold, auto_stop)


@cli.command()
@cli.command(name="ocr")
@click.option('-i', '--image', prompt='图片路径', help='图片路径')
def ocr(image: str) -> None or str:
def cli_ocr(image: str) -> None or str:
"""识别图片"""
# 文件不存在
if not os.path.isfile(image):
Expand Down Expand Up @@ -112,7 +119,7 @@ def ocr(image: str) -> None or str:
return result


@cli.command()
def version():
@cli.command(name="version")
def cli_version():
"""输出当前版本"""
click.echo(f"{__version__} ({__date__})")
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

if __name__ == '__main__':
if len(sys.argv) == 1:
esurfingpy.log.warning("无参数运行,即将打开图形界面……")
esurfingpy.Gui().run()
else:
esurfingpy.cli()

0 comments on commit db9f0ae

Please sign in to comment.