Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions 今日校园/actions/rlMessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,51 @@
# 若离消息通知类
class RlMessage:
# 初始化类
def __init__(self, mail, apiUrl):
def __init__(self, mail, sc, pp):
self.mail = mail
self.apiUrl = apiUrl
self.sc = sc
self.pp = pp
# 发送推送总模块
def send(self,status,msg):
result=[]
result.append(RlMessage.sendMail(self, status, msg))
result.append(RlMessage.sendSC(self, status, msg))
result.append(RlMessage.sendPP(self, status, msg))
return '\n'.join(result)

# 发送邮件消息
def sendMail(self, status, msg):
# 若离邮件api, 将会存储消息到数据库,并保存1周以供查看,请勿乱用,谢谢合作
if self.mail == '':
return '邮箱为空,已取消发送邮件!'
api = 'http://mail.ruoli.cc/api/sendMail'
params = {
'to': self.mail,
'title': f'[{status}]今日校园通知',
'content': msg
}
res = requests.post(url=self.apiUrl, params=params).json()
res = requests.post(url=api, params=params).json()
return res['msg']
# 其他通知方式待添加
# Server酱Turbo通知
def sendSC(self, status, msg):
if self.sc=='':
return 'SC为空,已取消发送微信!'
api = f'https://sctapi.ftqq.com/{self.sc}.send'
data = {
'title': msg,
"desp": f'[{status}]今日校园通知'
}
res=requests.post(api,data = data)
return res.json()['data']['error']
# Pushplus推送
def sendPP(self, status, msg):
if self.pp=='':
return 'PP为空,已取消发送PushPlus!'
api = 'http://www.pushplus.plus/send'
data = {
'token': self.pp,
'title': f'[{status}]今日校园通知',
"content": msg
}
res=requests.post(api,data = data)
return res.json()['msg']
18 changes: 17 additions & 1 deletion 今日校园/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ users:
address: '宜宾市(自己改)'
#email 接受通知消息的邮箱
email: ''
#Server酱Turbo的PUSHKEY(请自行注册获取)https://sct.ftqq.com/
sc : ''
#PushPlus的token http://pushplus.plus/
pp : ''
# 附上经纬度查询地址(请自行选择自己的学校地址,address,lon,lat都要填查询到的):http://api.map.baidu.com/lbsapi/getpoint/index.html
#lon 经度
lon: 104.616858
Expand Down Expand Up @@ -73,6 +77,10 @@ users:
address: '四川省(自己改)'
#email 接受通知消息的邮箱
email: ''
#Server酱Turbo的PUSHKEY(请自行注册获取)https://sct.ftqq.com/
sc : ''
#PushPlus的token http://pushplus.plus/
pp : ''
# 附上经纬度查询地址(请自行选择自己的学校地址,address,lon,lat都要填查询到的):http://api.map.baidu.com/lbsapi/getpoint/index.html
# 经纬度信息
lon: 104.6191824
Expand Down Expand Up @@ -117,6 +125,10 @@ users:
address: ''
#email 接受通知消息的邮箱,通知功能暂时未写
email: ''
#Server酱Turbo的PUSHKEY(请自行注册获取)https://sct.ftqq.com/
sc : ''
#PushPlus的token http://pushplus.plus/
pp : ''
#school 学校全称
schoolName: 武汉船舶职业技术学院
# 附上经纬度查询地址(请自行选择自己的学校地址,address,lon,lat都要填查询到的):http://api.map.baidu.com/lbsapi/getpoint/index.html
Expand Down Expand Up @@ -154,6 +166,10 @@ users:
address: ''
#email 接受通知消息的邮箱
email: ''
#Server酱Turbo的PUSHKEY(请自行注册获取)https://sct.ftqq.com/
sc : ''
#PushPlus的token http://pushplus.plus/
pp : ''
# 附上经纬度查询地址(请自行选择自己的学校地址,address,lon,lat都要填查询到的):http://api.map.baidu.com/lbsapi/getpoint/index.html
#lon 经度
lon: 105.895856
Expand All @@ -162,4 +178,4 @@ users:
#abnormalReason 反馈信息(这个一般不用配置,但是不能删除,删除会报错)
abnormalReason: ''
#photo 签到照片,不需要可不填,或者直接删除
photo: sign.jpg
photo: sign.jpg
25 changes: 17 additions & 8 deletions 今日校园/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import yaml
import time
from todayLoginService import TodayLoginService
from actions.autoSign import AutoSign
from actions.collection import Collection
Expand All @@ -18,18 +19,26 @@ def getYmlConfig(yaml_file='config.yml'):
def main():
config = getYmlConfig()
for user in config['users']:
rl = RlMessage(user['user']['email'], config['emailApiUrl'])
rl = RlMessage(user['user']['email'],user['user']['sc'],user['user']['pp'])
max_tries = 0
if config['debug']:
msg = working(user)
else:
try:
msg = working(user)
except Exception as e:
msg = str(e)
print(msg)
msg = rl.sendMail('error', msg)
while max_tries < 5:
try:
msg = working(user)
print(msg)
msg = rl.send('成功', msg)
break;
except Exception as e:
msg = str(e)
print(msg)
time.sleep(5)
print('出错!五秒后重试……')
if max_tries >= 4:
msg = rl.send('出错', msg)
max_tries+=1
print(msg)
msg = rl.sendMail('maybe', msg)

def working(user):
today = TodayLoginService(user['user'])
Expand Down