> 文档中心 > 疫情防控通每日自动汇报讲解

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


首先完成python模拟网页日汇报页面的场景

 代码段:

import osimport requestsimport jsonimport lxml.htmlimport 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= signIn,     timeout=10)historyResponse = conn.get(    url="https://app.upc.edu.cn/ncov/wap/default/index?from=history",    headers=headers,    data={'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].textdefault = 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 = oldInfonewInfo = 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 = dic,    timeout=10)saveJson = json.loads(saveResponse.text)print(saveJson['m'])

再进入Setting——>Secret界面设置变量USERNAME和PASSWORD,并输入自己学号密码

 

下一步,在Action中选择python package,配置yml文件(贴入代码)

# 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 paralleljobs:  # 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 # 执行代码

完成配置后等待每日执行即可

 附上github链接:https://github.com/yyf0101/upc