-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change cli folder name and add cli.token module
- Loading branch information
1 parent
4bd6122
commit c33fe32
Showing
7 changed files
with
48 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
token | ||
__pycache__ | ||
|
||
.token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from cli.main import main |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import questionary | ||
from get_token import check_token_expired, get_token | ||
import os.path as path | ||
|
||
TOKEN_PATH = ".token" | ||
|
||
|
||
def load_token(): | ||
token = "" | ||
print("读取token文件中...") | ||
|
||
if path.exists(TOKEN_PATH): | ||
with open(TOKEN_PATH) as f: | ||
token = f.read().strip() | ||
|
||
if check_token_expired(token): | ||
print("token过期") | ||
login() | ||
else: | ||
print("token读取成功") | ||
else: | ||
token = login() | ||
|
||
return token | ||
|
||
|
||
def login(): | ||
print("请先使用统一认证账号登陆获取token") | ||
username = questionary.text("学号:").ask() | ||
password = questionary.password("密码:").ask() | ||
|
||
if not username or not password: | ||
print("请输入用户名和密码") | ||
exit() | ||
|
||
token = get_token(username, password) | ||
print("登陆成功,写入token文件") | ||
|
||
with open(TOKEN_PATH, "w+") as f: | ||
f.write(token) | ||
|
||
return token |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from gzic_bus_cli import main | ||
from cli import main | ||
|
||
|
||
if __name__ == "__main__": | ||
|