Files
EnuivTools/scripts/login_check.py
T

52 lines
1.5 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]))
from euniv_client 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:
session = client.open_session()
finally:
client.close()
info = session["profile"]
summary = session["summary"]
fields = [
("工号", info.get("username")),
("姓名", info.get("cnName")),
("部门", info.get("departmentName")),
("岗位层级", info.get("userClassLevelName")),
("邮箱", info.get("email")),
("累计学时", summary.get("actual_study_hour")),
("累计学分", summary.get("actual_study_score")),
("积分", summary.get("points")),
("今日学时", summary.get("today_hours")),
("今日学分", summary.get("today_score")),
]
print("登录成功")
for label, value in fields:
if value is not None and 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)