Skip to content

Commit

Permalink
add nofity()
Browse files Browse the repository at this point in the history
  • Loading branch information
yp51md committed Feb 25, 2021
1 parent e28fe7b commit 779a8d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
name: NJUcheckin

on:
[
push,
schedule:
- cron: '00 03 * * *'
- cron: '01 00 * * *'
]


jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- fork 本代码库
- 配置 Setting-Secrets 添加
- USERNAME:学号
- PASSWORD:密码
- PASSWORD:统一身份认证密码
- RECEIVERMAILUSERNAME:接收邮件的邮箱
- MAILUSERNAME:发送邮件的163邮箱
- MAILPASSWORD:发送邮件的163邮箱的密码
Expand Down
33 changes: 25 additions & 8 deletions njucheckin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
'User-Agent': UserAgent
}

def notify(meg):
with open('email.txt','a+') as f:
f.write(msg,'\n')
return

class Njuer:

Expand Down Expand Up @@ -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()
Expand All @@ -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']
Expand All @@ -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__":
Expand All @@ -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)

0 comments on commit 779a8d1

Please sign in to comment.