diff --git a/.github/workflows/auto-sign-action.yml b/.github/workflows/auto-sign-action.yml new file mode 100644 index 0000000..fabb0ff --- /dev/null +++ b/.github/workflows/auto-sign-action.yml @@ -0,0 +1,65 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: auto-sign + +on: + push: + branches: [ master ] + schedule: + - cron: 30,0,57,27 16 * * * + # watch: + # types: started + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + env: + TZ: Asia/Shanghai + + steps: + + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Setup Java JRE + uses: actions/setup-java@v1.4.3 + with: + java-version: 1.8 + java-package: jre + - name: Get pip cache dir + id: pip-cache + run: | + echo "::set-output name=dir::$(pip cache dir)" + + - name: pip cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Prepare the jobs + run: | + sudo apt install tesseract-ocr tesseract-ocr-chi-sim + sudo apt install tesseract-ocr-eng + curl -L -v -o temp.jar https://github.com/ZimoLoveShuang/wisedu-unified-login-api/releases/download/v1.0.8/wisedu-unified-login-api-v1.0.jar + ls + pwd + java -version + (java -jar ./temp.jar &) + python3 -m pip install --upgrade pip + pip install setuptools flake8 wheel + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Run with schedule. + run: | + python3 index.py diff --git a/config.yml b/config.yml index 5dce0e3..d78e39b 100644 --- a/config.yml +++ b/config.yml @@ -10,8 +10,8 @@ users: username: '161105024' #password 密码 password: '161105024' - #address 地址,定位信息 - address: 中国河南省xx市xx区xx路 + #address 地址,定位信息 中国河南省xx市xx区xx路 + address: 中国河南省 #email 接受通知消息的邮箱 email: 461009747@qq.com #school 学校全称 @@ -42,4 +42,4 @@ cpdaily: # #表单项标题 # title: 体温 # #表单项默认值 -# value: 正常 \ No newline at end of file +# value: 正常 diff --git a/index.py b/index.py index 42cb3ec..9d5b645 100644 --- a/index.py +++ b/index.py @@ -12,7 +12,7 @@ from urllib3.exceptions import InsecureRequestWarning # debug模式 -debug = False +debug = True if debug: requests.packages.urllib3.disable_warnings(InsecureRequestWarning) @@ -104,11 +104,16 @@ def getSession(user, apis): cookies = {} # 借助上一个项目开放出来的登陆API,模拟登陆 - res = requests.post(url=config['login']['api'], data=params, verify=not debug) + res = '' + try: + res = requests.post(url=config['login']['api'], data=params, verify=not debug) + except Exception as e: + res = requests.post(url='http://127.0.0.1:8080/wisedu-unified-login-api-v1.0/api/login', data=params, verify=not debug) + # cookieStr可以使用手动抓包获取到的cookie,有效期暂时未知,请自己测试 # cookieStr = str(res.json()['cookies']) cookieStr = str(res.json()['cookies']) - log(cookieStr) + # log(cookieStr) 调试时再输出 if cookieStr == 'None': log(res.json()) exit(-1) @@ -123,8 +128,8 @@ def getSession(user, apis): return session -# 获取最新未签到任务 -def getUnSignedTasks(session, apis): +# 获取最新未签到任务并全部签到 +def getUnSignedTasksAndSign(session, apis, user): headers = { 'Accept': 'application/json, text/plain, */*', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36', @@ -145,11 +150,18 @@ def getUnSignedTasks(session, apis): log('当前没有未签到任务') exit(-1) # log(res.json()) - latestTask = res.json()['datas']['unSignedTasks'][0] - return { - 'signInstanceWid': latestTask['signInstanceWid'], - 'signWid': latestTask['signWid'] - } + for i in range(0, len(res.json()['datas']['unSignedTasks'])): + #if '出校' in res.json()['datas']['unSignedTasks'][i]['taskName'] == False: + # if '入校' in res.json()['datas']['unSignedTasks'][i]['taskName'] == False: + latestTask = res.json()['datas']['unSignedTasks'][i] + params = { + 'signInstanceWid': latestTask['signInstanceWid'], + 'signWid': latestTask['signWid'] + } + task = getDetailTask(session, params, apis) + form = fillForm(task, session, user, apis) + + submitForm(session, user, form, apis) # 获取签到任务详情 @@ -259,7 +271,7 @@ def submitForm(session, user, form, apis): "lon": user['lon'], "model": "OPPO R11 Plus", "appVersion": "8.1.14", - "systemVersion": "4.4.4", + "systemVersion": "8.0", "userId": user['username'], "systemName": "android", "lat": user['lat'], @@ -292,16 +304,25 @@ def submitForm(session, user, form, apis): # 发送邮件通知 def sendMessage(msg, email): send = email - if send != '': - log('正在发送邮件通知。。。') - res = requests.post(url='http://www.zimo.wiki:8080/mail-sender/sendMail', - data={'title': '今日校园自动签到结果通知', 'content': msg, 'to': send}, verify=not debug) - code = res.json()['code'] - if code == 0: - log('发送邮件通知成功。。。') - else: - log('发送邮件通知失败。。。') - log(res.json()) + if msg.count("未开始")>0: + return '' + try: + if send != '': + log('正在发送邮件通知。。。') + log(getTimeStr()) + # sendMessageWeChat(msg + getTimeStr(), '今日校园自动签到结果通知') + + res = requests.post(url='http://www.zimo.wiki:8080/mail-sender/sendMail', + data={'title': '今日校园自动签到结果通知' + getTimeStr(), 'content': msg, 'to': send}, verify=not debug) + code = res.json()['code'] + if code == 0: + log('发送邮件通知成功。。。') + else: + log('发送邮件通知失败。。。') + log(res.json()) + except Exception as e: + log("send failed") + # 主函数 @@ -309,11 +330,7 @@ def main(): for user in config['users']: apis = getCpdailyApis(user) session = getSession(user, apis) - params = getUnSignedTasks(session, apis) - task = getDetailTask(session, params, apis) - form = fillForm(task, session, user, apis) - # form = getDetailTask(session, user, params, apis) - submitForm(session, user, form, apis) + getUnSignedTasksAndSign(session, apis, user) # 提供给腾讯云函数调用的启动函数