python|疫情防控通每日自动汇报讲解

首先完成python模拟网页日汇报页面的场景
代码段:
import os import requests import json import lxml.html import resignIn = {'username': os.environ["USERNAME"], #学号 'password': os.environ["PASSWORD"]} #登陆密码headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Mobile Safari/537.36', }conn = requests.Session() signInResponse= conn.post( url="https://app.upc.edu.cn/uc/wap/login/check", headers=headers, data= https://www.it610.com/article/signIn, timeout=10 )historyResponse = conn.get( url="https://app.upc.edu.cn/ncov/wap/default/index?from=history", headers=headers, data=https://www.it610.com/article/{'from': 'history'}, timeout=10 ) historyResponse.encoding = "UTF-8"html = lxml.html.fromstring(historyResponse.text) JS = html.xpath('/html/body/script[@type="text/javascript"]') JStr = JS[0].text default = re.search('var def = {.*}; ',JStr).group() oldInfo = re.search('oldInfo: {.*},',JStr).group()firstParam = re.search('sfzgsxsx: .,',JStr).group() firstParam = '"' + firstParam.replace(':','":') secondParam = re.search('sfzhbsxsx: .,',JStr).group() secondParam = '"' +secondParam.replace(':','":') lastParam = re.search('szgjcs: \'(.*)\'',JStr).group() lastParam = lastParam.replace('szgjcs: \'','').rstrip('\'')newInfo = oldInfo newInfo = newInfo.replace('oldInfo: {','{' + firstParam + secondParam).rstrip(',')defaultStrip = default.replace('var def = ','').rstrip('; ') defdic = json.loads(defaultStrip)dic = json.loads(newInfo) dic['ismoved'] = '0' for j in ["date","created","id","gwszdd","sfyqjzgc","jrsfqzys","jrsfqzfy"]: dic[j] = defdic[j] dic['szgjcs'] = lastParamsaveResponse = conn.post( url="https://app.upc.edu.cn/ncov/wap/default/save", headers=headers, data = https://www.it610.com/article/dic, timeout=10 )saveJson = json.loads(saveResponse.text) print(saveJson['m'])

再进入Setting——>Secret界面设置变量USERNAME和PASSWORD,并输入自己学号密码
python|疫情防控通每日自动汇报讲解
文章图片

python|疫情防控通每日自动汇报讲解
文章图片

python|疫情防控通每日自动汇报讲解
文章图片

下一步,在Action中选择python package,配置yml文件(贴入代码)
python|疫情防控通每日自动汇报讲解
文章图片


# This is a basic workflow to help you get started with Actionsname: Daily Submit# Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the main branch schedule: - cron: '1 0,23 * * *'# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" submit: runs-on: ubuntu-latest # 定义系统类型,这里选择Ubuntu steps: - name: '[Prepare] Code Check' uses: actions/checkout@v2 # 从该仓库clone代码到虚拟机 - name: '[Prepare] Set python' uses: actions/setup-python@v1 # 安装python with: python-version: '3.x' - name: '[Prepare] Install Dependencies' run: | python -m pip install --upgrade pip python -m pip install --upgrade lxml python -m pip install --upgrade requests # 安装需要的python库 - name: '[Final Main] Working' env: USERNAME: ${{ secrets.USERNAME }} PASSWORD: ${{ secrets.PASSWORD }} run: | python main.py # 执行代码

完成配置后等待每日执行即可
【python|疫情防控通每日自动汇报讲解】 附上github链接:https://github.com/yyf0101/upc

    推荐阅读