try:
    username = os.environ["xmu_username"]
    password = os.environ["xmu_password"]
except KeyError:
    reason = "You must provide a valid username & password to log in xmuxg.xmu.edu.cn!"
    print(reason)
    report_with_server_chan(False, reason)
    sys.exit(1)

try:
    today_log, status = check_recent(username, password)
    if status == 0 and today_log["today"]:
        print("Already reported today :)")
        sys.exit(0)

    response, status = health_report(username, password)
    if status != 0:
        print("Report error, reason: " + response["reason"])
        report_with_server_chan(False, response["reason"])
        sys.exit(1)

    today_log, status = check_recent(username, password)
    if status == 0:
        if today_log["today"]:
            print("Automatically reported successfully!")
            success_info = "当前连续打卡" + str(today_log["days"]) + "天,健康码为" + str(
                today_log["color"]) + "码!"
            report_with_server_chan(True, success=success_info)
            sys.exit(0)
        else:
            print("Automatically reported failed.")
Esempio n. 2
0
                    help="动作 (check: 打卡,query: 查询今日打卡情况)")
parser.add_argument('--webvpn',
                    choices=["true", "false"],
                    help="是否通过 WebVPN 发送请求")
parser.add_argument('--vpn-username',
                    metavar='vpn_username',
                    help="WebVPN 用户名")
parser.add_argument('--vpn-password', metavar='vpn_password', help="WebVPN 密码")

args = parser.parse_args()

username = args.username
password = args.password
use_webvpn = args.webvpn == "true"

if args.action == "check":
    res, sta = health_report(username,
                             password,
                             use_webvpn=use_webvpn,
                             vpn_username=args.vpn_username,
                             vpn_password=args.vpn_password)
    print(json.dumps(res, indent=4, ensure_ascii=False))

if args.action == "query":
    res, sta = check_recent(username,
                            password,
                            use_webvpn=use_webvpn,
                            vpn_username=args.vpn_username,
                            vpn_password=args.vpn_password)
    print(json.dumps(res, indent=4, ensure_ascii=False))