コード例 #1
0
def auto_add_zzut_full_values(file_path):

    name_table_full_values_json = read_json_file(file_path)

    inform_content_head = "<table id=\"customers\"><tr><th>打卡学号</th><th>打卡时间</th><th>打卡状态</th></tr>"
    inform_content_tail = "</table>"

    login_url_cookie = ''
    # 循环执行打卡
    for values in name_table_full_values_json['names']:
        if login_url_cookie == '':
            # 获取的是当前帐号的专属cookie
            login_url_cookie = get_login_cookie(values["xh"])
        else:
            # 如果不为空,刷新cookie所有权
            refresh_cookie(login_url_number=values["xh"],
                           cookie=login_url_cookie)

        results = add_zzut_full_values(values=values, cookie=login_url_cookie)
        if 'code' in results:
            if results['code'] != "1":
                # 有几率是已经打过卡造成的异常,但以防万一,重新获取专属cookie打卡一次
                login_url_cookie = get_login_cookie(values["xh"])
                results = add_zzut_full_values(values=values,
                                               cookie=login_url_cookie)

        inform_content_head += "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % (
            values["xh"], datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            analyse_status(results=results))
        write_log_file(number=values["xh"], results=results)
    write_temp_report_file(content=inform_content_head + inform_content_tail)
コード例 #2
0
def write_temp_report_file(content):

    file_name = datetime.now().strftime("%Y-%m-%d")
    file_name += "_report_file.txt"
    file_status = 0
    if not os.path.isfile(BASE_DIR + '/zzut/log/' + file_name):
        file_status = 1

    # 以追加形式打开日志文件
    report_file = open(BASE_DIR + '/zzut/log/' + file_name,
                       'a',
                       encoding='UTF-8')
    if file_status == 1:
        inform_account_json_file = read_json_file(BASE_DIR +
                                                  "/zzut/data/mail_user.json")
        inform_content = inform_account_json_file["content_css"]
        report_file.write(inform_content)
    report_file.write(content)
    report_file.close()
コード例 #3
0
def report_mail():
    file_name = datetime.now().strftime("%Y-%m-%d")
    file_name += "_report_file.txt"
    # 读取报告文件
    report_file = open(BASE_DIR + '/zzut/log/' + file_name,
                       "r",
                       encoding='UTF-8')
    report_file_str = ""
    for line in report_file:
        report_file_str = report_file_str + line
    report_file.close()

    inform_account_json_file = read_json_file(BASE_DIR +
                                              "/zzut/data/mail_user.json")
    send_mail(server=inform_account_json_file["server"],
              user=inform_account_json_file["user"],
              passwd=inform_account_json_file["passwd"],
              subject=inform_account_json_file["subject"],
              to_user=inform_account_json_file["to_user"],
              content=report_file_str)
コード例 #4
0
def auto_rd_add_zzut_values(file_path):

    name_table_value_json = read_json_file(file_path)

    names_table = []
    # 获取总表
    for values in name_table_value_json['names']:
        names_table.append(Student(values))

    if len(names_table) == 0:
        return
    # 打乱顺序
    random.shuffle(names_table)
    # 理论打卡间隔时间为3600/总人数+浏览器cookie获取时间(大约15-20s),计划分布在一个小时内,加上网络耗时,单个打卡预计20s+3600/总人数
    interval_time = 3600 / len(names_table)
    # 邮件报告信息头与信息尾
    inform_content_head = "<table id=\"customers\"><tr><th>打卡学号</th><th>打卡时间</th><th>打卡状态</th></tr>"
    inform_content_tail = "</table>"
    for people in names_table:
        login_url_cookie = get_login_cookie(people.data["xh"])
        base_heat = [36.5, 36.5, 36.5]
        for i in range(0, 3):
            base_heat[i] += random.choice([0.3, 0.2, 0.1, 0, -0.1])
        results = add_zzut_values(address=people.data["dqwzmc"],
                                  class_and_grade=people.data["bjmc"],
                                  number=people.data["xh"],
                                  academy=people.data["szdwmc"],
                                  current_position_number=people.data["dqwz"],
                                  name=people.data["xm"],
                                  cookie=login_url_cookie,
                                  animal_heat=base_heat)
        # 信息内容
        inform_content_head += "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % (
            people.data["xh"], datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            analyse_status(results=results))
        write_log_file(number=people.data["xh"], results=results)
        time.sleep(interval_time)
    write_temp_report_file(content=inform_content_head + inform_content_tail)