西电晨午晚检自动填报(python实现)

导员每天催的晨午晚检实在太烦了,一次忘记填,又是要写反思又是要被记小本本。如果能自动填就万事大吉了,于是我参照GitHub上校友发布的程序,实现了这一想法。

在最下面的 main_handler 填入信息,student_id 是学号,password 是西电一站式的密码。除此之外,强烈推荐填写 SCKEY 。这是基于 Server 酱的微信推送服务,只需要 1 分钟就可以完成注册,然后把 SCKEY 填入就可以收到每次签到情况的推送。

本地如果有 Python3 + requests 环境,可以先进行调试,观察输出是否正常,不调试也没大问题。

每次运行脚本相当于触发一次签到动作,还需要做到定时运行脚本。建议使用腾讯云的函数计算。

函数计算
进入 https://cloud.tencent.com/product/scf 的管理控制台里的函数服务

新建

填写信息,名称随意

填入代码,测试,完成

触发管理-创建触发器

填入信息,名称随意。Cron 填入

0 3 6,12,18 * * * *
意为每天 6:03:00 12:03:00 18:03:00 定时触发

完成

py程序`

import requests
import json
import time
import pytz
import datetime

def login(session, username, password):
    headers = {
        'Connection': 'keep-alive',
        'Pragma': 'no-cache',
        'Cache-Control': 'no-cache',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'X-Requested-With': 'XMLHttpRequest',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 Edg/84.0.522.40',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Origin': 'https://xxcapp.xidian.edu.cn',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Referer': 'https://xxcapp.xidian.edu.cn/uc/wap/login',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    }

    data = {
        'username': username,
        'password': password
    }

    response = session.post(
        'https://xxcapp.xidian.edu.cn/uc/wap/login/check', headers=headers, data=data)
    # print(response.status_code, response.cookies)


def commit(session):
    headers = {
        'Host': 'xxcapp.xidian.edu.cn',
        'Accept': 'application/json, text/plain, */*',
        'X-Requested-With': 'XMLHttpRequest',
        'Accept-Language': 'zh-cn',
        'Accept-Encoding': 'gzip, deflate, br',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Origin': 'https://xxcapp.xidian.edu.cn',
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.14(0x17000e27) NetType/WIFI Language/zh_CN',
        'Connection': 'keep-alive',
        'Referer': 'https://xxcapp.xidian.edu.cn/site/ncov/xidiandailyup',
        'Content-Length': '1835',
    }

    data = {
        'sfzx': '1',
        'tw': '1',
        'area': '陕西省 西安市 长安区',
        'city': '西安市',
        'province': '陕西省',
        'address': '陕西省西安市长安区兴隆街道梧桐大道西安电子科技大学长安校区',
        'geo_api_info': '{"type":"complete","position":{"Q":34.129092068143,"R":108.83138888888902,"lng":108.831389,"lat":34.129092},"location_type":"html5","message":"Get geolocation success.Convert Success.Get address success.","accuracy":65,"isConverted":true,"status":1,"addressComponent":{"citycode":"029","adcode":"610116","businessAreas":[],"neighborhoodType":"","neighborhood":"","building":"","buildingType":"","street":"雷甘路","streetNumber":"266#","country":"中国","province":"陕西省","city":"西安市","district":"长安区","township":"兴隆街道"},"formattedAddress":"陕西省西安市长安区兴隆街道梧桐大道西安电子科技大学长安校区","roads":[],"crosses":[],"pois":[],"info":"SUCCESS"}',
        'sfcyglq': '0',
        'sfyzz': '0',
        'qtqk': '',
        'ymtys': '0'
    }

    response = session.post('https://xxcapp.xidian.edu.cn/xisuncov/wap/open-report/save',
                            headers=headers, data=data)

    # print(response.status_code, response.text)
    return response


def commit_data(username, password):
    sess = requests.session()
    login(sess, username, password)
    res = commit(sess)
    js = json.loads(res.text)
    return js['m']


def server_jiang_push(SCKEY: str, message):
    requests.get(f'https://sc.ftqq.com/{SCKEY}.send?text={message}')


def send_log(student_id, message):
    js = json.dumps({"student_id": str(student_id),
                     "message": message}, ensure_ascii=False).encode('utf-8')

    res = requests.post(
        'http://XduCheckInLog.117503445.top:8013/api/log', data=js)
    if res.text == 'success':
        print('log success')

# return '晨' or '午' or '晚' or '凌晨'


def get_hour_message():
    h = datetime.datetime.fromtimestamp(int(time.time()),pytz.timezone('Asia/Shanghai')).hour
    if 6 <= h <= 11:
        return '晨'
    elif 12 <= h <= 17:
        return '午'
    elif 18 <= h <= 24:
        return '晚'
    else:
        return '凌晨'


def main_handler(event, context):

    student_id = '这里输入学号'
    password = '这里输入密码'  # http://ids.xidian.edu.cn/authserver/login

    # https://sc.ftqq.com/3.version
    # 基于 Server 酱的推送服务,
    SCKEY = '输入你注册绑定的sckey'

    # 丨是汉字,微信标题不能有符号
    message = get_hour_message() + '检丨' + commit_data(student_id, password)
    if SCKEY != '':
        server_jiang_push(SCKEY, message)

    send_log(student_id, message)  # 可选,上传日志,帮助开发者优化程序:D


if __name__ == "__main__":
    main_handler(None,None)

更详细的教程放在我的公众号“我有一计”之中,如嫌麻烦,可与我私信,告知学号密码即可。

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 我行我“速” 设计师:Amelia_0503 返回首页