python青年⼤学习⼀键提醒功能完整代码视频讲解详细
Bilibili:
⽂字详细过程可移步到
github:
gitee:
import requests
from import MIMEText
import smtplib
from time import sleep
import pytesseract
from PIL import Image, ImageEnhance
from selenium import webdriver
username =input("请输⼊⼿机号:")
password =input("请输⼊密码:")
DidDone =[]
session = requests.Session()
BASE_INFO ={
"abbreviation":"",
"orgId":"",
"address":"",
"orgName":"",
}
Email =[
['11111@qq','张三'],['22222@qq','李四'],
['333333@qq','⽼王'],['444444@qq','⼩王'],# TODO 这⾥记得要改
]
def GetCookie(username, password):
try:
url ='m.fjcyl/login'
chrome_path =r"D:\Download\Dirver\chromedriver_"
# TODO 驱动的路径,记得换成你的驱动
driver = webdriver.Chrome(executable_path=chrome_path)
<(url)
# sleep(1) # 等待⽹络
driver.find_element_by_id('userName').clear()
driver.find_element_by_id('userName').send_keys(username)
driver.find_element_by_id('pwd').clear()
driver.find_element_by_id('pwd').send_keys(password)
driver.save_screenshot("./TempImage/01.png")# 截取屏幕内容,保存到本地
ran = Image.open("./TempImage/01.png")# 打开截图,获取验证码位置,截取保存验证码
box =(900,690,980,750)
# 获取验证码位置,⾃动定位不是很明⽩,就使⽤了⼿动定位,代表(左,上,右,下)
# 获取验证码图⽚,读取验证码
imageCode = Image.open("./TempImage/02.png")# 打开保存的验证码图⽚
sharp_img = ImageEnhance.Contrast(imageCode).enhance(2.0)# 图像增强,⼆值化
sharp_img = ImageEnhance.Contrast(imageCode).enhance(2.0)# 图像增强,⼆值化
sharp_img.save("./TempImage/03.png")# 保存图像增强,⼆值化之后的验证码图⽚
sharp_img.load()# 对⽐度增强
img = Image.open('./TempImage/03.png')
img = vert('RGB')# 这⾥也可以尝试使⽤L
enhancer = ImageEnhance.Color(img)
enhancer = hance(0)
enhancer = ImageEnhance.Brightness(enhancer)
enhancer = hance(2)
enhancer = ImageEnhance.Contrast(enhancer)
enhancer = hance(8)
enhancer = ImageEnhance.Sharpness(enhancer)
img = hance(20)
code = pytesseract.image_to_string(img)
print(code)# 输出验证码
driver.find_element_by_id('VALIDATE_CODE').send_keys(code)
element1 = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/input")
dictCookies = _cookies()# 获取cookie
selenium获取cookiesleep(2)
driver.close()
return dictCookies[0]["value"]
except Exception as err:
return"500"
# 请求头
headers ={
'Host':'m.fjcyl',
'Referer':'m.fjcyl/',
'User-Agent':'Mozilla/5.0 (iPad; CPU OS 13_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) ' 'Mobile/15E148 MicroMessenger/7.0.12(0x17000c33) NetType/WIFI Language/zh_CN',
'Cookie':'JSESSIONID='+GetCookie(username, password)
}
def GetSchoolInfo():# 学校信息
try:
URL ="m.fjcyl/admin/user/orgList"
info_rsp = session.post(url=URL, headers=headers)
info_json = info_rsp.json()
abbreviation = info_json["rs"][0]["cylorganization"]["abbreviation"]# 19⼤数据
orgId = info_json["rs"][0]["cylorganization"]["orgId"]# 个⼈id
address = info_json["rs"][0]["cylorganization"]["address"]# 福州⼤学
orgName = info_json["rs"][0]["cylorganization"]["orgName"]# 福州⼤学数学与计算机科学学院2019级⼤数据团⽀部 BASE_INFO["abbreviation"]= abbreviation
BASE_INFO["orgId"]= orgId
BASE_INFO["address"]= address
BASE_INFO["orgName"]= orgName
# print("BASE_INFO")
# print(BASE_INFO)
return BASE_INFO
except Exception as err:
print(err)
return"500"
def LastestNum():# 获取最新⼀期的青年⼤学习的id
URL ="m.fjcyl/admin/cylOrgMembers/groupByList?groupBy=1"
info = URL
info_rsp = session.post(url=info, headers=headers)
info_json = info_rsp.json()
x = info_json['rs'][0]['quarterNo']
return x
def LastestURL():# 获取最新的链接,id是⽇期
def LastestURL():# 获取最新的链接,id是⽇期
num = LastestNum()
URL ="m.fjcyl/admin/cylOrgMembers/selectList?orderBy=1&quarterNo={}".format(num)
info = URL
info_rsp = session.post(url=info, headers=headers)
info_json = info_rsp.json()
Ls = info_json["rs"]
StudyTdLists =[]
for k in Ls:
StudyTdLists.append(k['guoupStudyId'])
return max(StudyTdLists)
def GetInfo(i):# 获取没做名单
num = LastestURL()
URL ="m.fjcyl/admin/cylOrgMembers/selectCurrentStudy?studyId={}&" \
"current=&PAGE_SIZE=20&CURRENT_PAGE={}&orgId={}".format(
num, i, BASE_INFO["orgId"])
info = URL
info_rsp = session.post(url=info, headers=headers)
info_json = info_rsp.json()
List = info_json["rs"]['rs']
# print(List)
for detail in List:
# if detail['isStudy'] == '是':
if detail['isStudy']!='是':
DidDone.append(detail['acctName'])
return DidDone
def Parma():# 我们班有3页,所以就直接这样了
Temp1 = GetInfo(1)
Temp2 = GetInfo(2)
Temp3 = GetInfo(3)
Temp = Temp1 + Temp2 + Temp3 # 这⾥是将没有做的同学记录下来
DidDoneEmail =[]# 这⾥是将没有做的同学记录下来
if len(Temp)==0:
print("全部都完成了")
return0
else:
for k in Temp:
print("未完成同学:"+ k)
for i in range(len(Email)):
if Email[i][0]in Temp:
DidDoneEmail.append(Email[i][1])
return DidDoneEmail
def Send_Email():
msg = MIMEText('青年⼤学习!不⽤回复!赶紧做!!')# 构造邮件,内容为青年⼤学习
msg["Subject"]="青年⼤学习!!⼜是你"# 设置邮件主题
msg["From"]=''# 寄件者
msg["To"]='未做⼈员'# 收件者
from_addr =''# TODO 这⾥记得写你的邮箱地址
password =''# TODO 这⾥记得更改上⾯from_addr的邮箱的申请码
smtp_server ='smtp.qq'# smtp服务器地址
to_addr = Parma()# 收件⼈地址
try:
# smtp协议的默认端⼝是25,QQ邮箱smtp服务器端⼝是465,第⼀个参数是smtp服务器地址,第⼆个参数是端⼝,第三个参数是超时设置,这⾥必须使⽤ssl 证书,要不链接不上服务器
server = smtplib.SMTP_SSL(smtp_server,465, timeout=2)
server.login(from_addr, password)# 登录邮箱
# 发送邮件,第⼀个参数是发送⽅地址,第⼆个参数是接收⽅列表,列表中可以有多个接收⽅地址,表⽰发送给多个邮箱,msg.as_string()将MIMEText对象转化成⽂本
server.sendmail(from_addr, to_addr, msg.as_string())
server.quit()
print('success')
except Exception as e:
if e ==None:
# Send_Boss()
print('Faild:%s'% e)
pass
if __name__ =='__main__': GetSchoolInfo()
# Parma()
Send_Email()
会有不⾜,希望⼤佬斧正!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论