Files
EnuivTools/scripts/login_check.py
T

47 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""命令行登录中兴 e 学并打印用户资料。资料只打印,不写入本地库。"""
from __future__ import annotations
import os
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "backend"))
from euniv import EunivClient
def main() -> int:
login_name = os.environ.get("EUNIV_LOGIN", "").strip()
password = os.environ.get("EUNIV_PASSWORD", "")
if not login_name or not password:
print("请设置环境变量 EUNIV_LOGIN 和 EUNIV_PASSWORD", file=sys.stderr)
return 2
client = EunivClient(login_name, password)
try:
profile = client.login()
client.authorize(profile)
info = client.user_info()
finally:
client.close()
fields = [
("工号", info.get("username")),
("姓名", info.get("cnName")),
("部门", info.get("departmentName")),
("岗位层级", info.get("userClassLevelName")),
("邮箱", info.get("email")),
]
print("登录成功")
for label, value in fields:
if value:
print(f"{label}:{value}")
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except Exception as exc:
print(str(exc), file=sys.stderr)
raise SystemExit(1)