河北科大每日晨午检(体温)利用python+github actions每日自动填报

请先看此篇文章,讲的很清楚。GitHub Action自动完成华工疫情打卡、网站自动签到
看懂后,直接使用代码即可。
python代码:此代码参考自体温自动填写,修改而成

# coding=utf-8
import requests as r
from lxml import etree
import time
from time import sleep

a, b, c, d, e, f, z = '', '', '', '', '', '', ''
timetamp = time.mktime(time.localtime())
timetamp = int(timetamp)
y=''
url = "http://xscfw.hebust.edu.cn/survey/ajaxLogin"
url2 = "http://xscfw.hebust.edu.cn/survey/index"
url3 = f"http://xscfw.hebust.edu.cn/survey/surveySave?timestamp={timetamp}"


# 账号信息
param = {
    "stuNum": "",#此处输入学号
    "pwd": "",#此处输入密码
    "vcode": "",
}
#
header = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62"
}


try:
    response = r.post(url=url, params=param, headers=header)
    sleep(20)
    cookiesJAR = response.cookies  # 获取cookies
    cookies = cookiesJAR.get_dict()  # 把cookies写成字典形式
    res = r.get(url=url2, headers=header, cookies=cookies, params=param)
    b = "正在登录,即学校网页可以正常进入"

except:
    b = "登录失败,即学校网页无法进入"



# 获取完成情况
try:
    res.encoding = 'uft-8'
    html = etree.HTML(res.text)
    content = html.xpath('/html/body/ul/li[1]/div/span/text()')
    y=content[0]
    c = "获取填报表单成功,即登录成功"

except:
    c = "获取填报表单失败,即登录失败"



# 获取当前日期要填的文档的sid
try:
    url4 = 'http://xscfw.hebust.edu.cn/survey/index.action'
    rek = r.get(url=url4, cookies=cookies, headers=header)
    rek.encoding = 'utf-8'
    html3 = etree.HTML(rek.text)
    sid = html3.xpath('/html/body/ul/li[1]/@sid')[0]
    d = "获取当前日期要填的文档的sid成功"

except:
    d = "获取当前日期要填的文档的sid失败"


#####获取stuId和qid
try:
    url5 = f'http://xscfw.hebust.edu.cn/survey/surveyEdit?id={sid}'
    rej = r.get(url=url5, cookies=cookies, headers=header)
    sleep(5)
    rej.encoding = 'utf-8'
    html2 = etree.HTML(rej.text)
    stuId = html2.xpath('//*[@id="surveyForm"]/input[2]/@value')[0]
    qid = html2.xpath('//*[@id="surveyForm"]/input[3]/@value')[0]
    e = "获取stuId qid 成功"

except:
    e = "获取stuId qid 失败"


try:
    data = {
        "id": sid,
        "stuId": stuId,
        "qid": qid,
        "location": '',
        "c0": "不超过37.3℃,正常",
        "c1": '36.5',
        "c3": "不超过37.3℃,正常",
        "c4": '36.5',
        "c6": "健康",
    }
    f = "获取信息成功"


except:
    f = "获取信息有误"


if y == '已完成':
    z = '早已完成填报,无需填报'


elif y == '未完成':
    try:
        timetamp = time.mktime(time.localtime())
        timetamp = int(timetamp)
        rep = r.post(url=url3, params=data, headers=header, cookies=cookies)
        a = "填报成功"
    except:
        a = "填报出错"



else:
    z = "填写时间未到,或填写失败"

file = open("mydata.html", 'w+', encoding='UTF-8')
file.write(b + '*****' + c + '*****' + d + '*****' + e + '*****' + f + '*****' + z + '*****' + a)
file.close()

yml代码:

name: tiwentianbao

on:
  workflow_dispatch: #在actions界面点击即可运行
  schedule:
    - cron: '10 2,3 * * *'  
  #在UTC时间2:10,3:10运行,也就是北京时间10点10分和11点10分
jobs:
  build:

    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
    - run:  pip install -r ./r.txt  #此处为安装依赖包
    - run: python ./python.py  #此处为python代码的文件名
   #发送邮件,可选
    - name: 'Send mail' 
      uses: dawidd6/action-send-mail@master
      with:
          # 这些是发送邮件需要配置的参数,更多详细的说明请访问具体的仓库
        server_address: smtp.163.com
        server_port: 465
          # 这些sectret的环境变量需要配置在setting中的secret下
        username: ${{ secrets.EMAILNAME }}  #变量名需与配置的一致
        password: ${{ secrets.EMAILPOP }}
        subject: 每日体温填报
        body: file://mydata.html
        to: [email protected]   #填写要收件邮箱名
        from: GitHub Actions
        content_type: text/html
        

依赖库txt文件:

requests
lxml

邮件效果:
河北科大每日晨午检(体温)利用python+github actions每日自动填报_第1张图片

你可能感兴趣的:(python)