From 779a8d19ff14b4cef7bab0b10862073eef4851d0 Mon Sep 17 00:00:00 2001 From: Gerrard Mao <41810562+yp51md@users.noreply.github.com> Date: Thu, 25 Feb 2021 12:07:58 +0800 Subject: [PATCH] add nofity() --- .github/workflows/blank.yml | 6 +++++- README.md | 2 +- njucheckin.py | 33 +++++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml index 32f918b..db6320b 100644 --- a/.github/workflows/blank.yml +++ b/.github/workflows/blank.yml @@ -3,8 +3,12 @@ name: NJUcheckin on: + [ + push, schedule: - - cron: '00 03 * * *' + - cron: '01 00 * * *' + ] + jobs: build: diff --git a/README.md b/README.md index 4fc7981..50c6890 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ - fork 本代码库 - 配置 Setting-Secrets 添加 - USERNAME:学号 - - PASSWORD:密码 + - PASSWORD:统一身份认证密码 - RECEIVERMAILUSERNAME:接收邮件的邮箱 - MAILUSERNAME:发送邮件的163邮箱 - MAILPASSWORD:发送邮件的163邮箱的密码 diff --git a/njucheckin.py b/njucheckin.py index a253609..88b56cc 100644 --- a/njucheckin.py +++ b/njucheckin.py @@ -22,6 +22,10 @@ 'User-Agent': UserAgent } +def notify(meg): + with open('email.txt','a+') as f: + f.write(msg,'\n') + return class Njuer: @@ -72,6 +76,20 @@ def login(self): self.session.post(loginUrl, data=data, headers=headers) return + def checkLogin(self): + res = self.session.get(hisUrl) + try: + res = json.loads(self.session.get(hisUrl).text) + print(res) + if res['code'] == 0: + print('登录成功') + notify('登录成功') + except Exception as e: + msg = '登录失败,请检查密码'+str(e) + print(msg) + notify(msg) + return + def exec_js_func(self, js_file, func, *params): with open(js_file, 'r') as f: lines = f.readlines() @@ -81,6 +99,7 @@ def exec_js_func(self, js_file, func, *params): return result def getCheckInfo(self): + checkLogin() res = self.session.get(hisUrl) resJson = json.loads(res.text) wid = resJson['data'][0]['WID'] @@ -93,17 +112,16 @@ def checkin(self): hisInfo = self.getCheckInfo() link = link.format(wid=str(hisInfo['wid']), curr_location=str(hisInfo['hisLoc']) + info) res = self.session.get(link) - res = json.loads(res.text) - f = open("email.txt", "w") + res = json.loads(res.text) if res['code'] == '0': if res['msg'] == '成功': + f = open("email.txt", "w") f.write("打卡成功!") print("打卡成功!") f.close() return 1 - f.write("打卡失败请检查action") + notify('打卡失败') print("打卡失败") - f.close() return 0 if __name__ == "__main__": @@ -116,8 +134,7 @@ def checkin(self): bot.checkin() except Exception as e: - f = open("email.txt", "w") - f.write("打卡失败,请手动打卡", str(e)) - print("打卡失败,请手动打卡", str(e)) - f.close() + msg = "打卡失败,请手动打卡"+ str(e) + notify(msg) + print(msg)