1 Star 0 Fork 0

LinXiaoDe/HealthCheck

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 3.22 KB
一键复制 编辑 原始数据 按行查看 历史
LinXiaoDe 提交于 2021-03-03 16:11 . update in 2021/3/3 add campus branch
import numpy as np
from mapper.getImage import getToken,getPic
from mapper.ksdemo import KSClient
from mapper.login import login
from mapper.sendEmail import sendEmail
from mapper.readData import readData
from mapper.commit import commit
import time
from apscheduler.schedulers.blocking import BlockingScheduler
from config.appConfig import *
# 打卡
def check(username,passwd,RealAddress,RealCity,RealCounty,RealProvince,IsInCampus):
imageName = username+".jpeg"
# 获取&下载图片
token = getToken(tokenURL)
print("获取token:",token)
if(token != "error"):
url = imageURL + "?token=" + token
getPic(url,dirPath,imageName)
# 获取验证码
Ks95man = KSClient()
verCode = ""
if Ks95man.GetTaken(k95Username,k95Passwd):
verCode = Ks95man.PostPic(dirPath+imageName,2)
print('识别结果:'+verCode)
# 登陆
response,cookie= login(loginUrl,username,passwd,token,verCode)
if response['code'] != 0: # 登陆失败
return -1
print("登陆成功")
# 提交信息
response = commit(commitUrl,RealAddress,RealCity,RealCounty,RealProvince,IsInCampus,cookie)
print(response)
return response['code']
# 循环打卡作业
def check_Job():
cur = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
print("----------[log] : "+cur)
# 读取用户信息
users = readData(dataPath)
# 最多进行3次打卡尝试 / day
for t in range(3):
# 保存打卡成功的用户下标 用于用户列表信息清除
sucessList = []
# 遍历用户列表
for i in range(1,len(users)):
username,passwd,email,RealAddress,RealCity,RealCounty,RealProvince,IsInCampus = users[i]
try:
res = check(username,passwd,RealAddress,RealCity,RealCounty,RealProvince,IsInCampus)
except:
res = -1
cur = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
# 打卡成功
if(res == 0):
sucessList.append(i)
sendEmail(senderEmail,email,AuthCode,sender,username,
"打卡成功提醒","Hi "+username+" :\n"+sucessMsg+cur+",祝您生活愉快!\n发件人: "+senderEmail)
# 重复打卡
elif(res == 1):
sucessList.append(i)
# 清理用户列表
users = np.delete(users,sucessList,0)
# 未成功打卡的用户发送邮箱提醒手动打卡
unCheck = ""
for i in range(1,len(users)):
username,passwd,email,RealAddress,RealCity,RealCounty,RealProvince,IsInCampus = users[i]
cur = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
print("错误",i)
sendEmail(senderEmail,email,AuthCode,
sender,username,"打卡失败提醒","Hi "+username+" :\n"+failMsg)
unCheck +=(username + '\n')
# 开发者邮件
if unCheck!="":
sendEmail(senderEmail,devEmail,AuthCode,sender,'Developer',
"打卡失败提醒(dev)","打卡出现问题,下列用户未打卡"+unCheck)
if __name__ == '__main__':
# 定点任务
sched = BlockingScheduler()
sched.add_job(check_Job,'cron',hour=checkHour,minute=checkMin)
sched.start()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/LinXiaoDe-Gitee/HealthCheck.git
git@gitee.com:LinXiaoDe-Gitee/HealthCheck.git
LinXiaoDe-Gitee
HealthCheck
HealthCheck
campus

搜索帮助