python青年大学习一键提醒功能 完整代码
【摘要】
视频讲解详细
Bilibili:点击这里
文字详细过程可移步到
详细分析(一) 详细分析(二)
github:
https://github.com/CocaineCong/TeenStudy ...
视频讲解详细
Bilibili:点击这里
文字详细过程可移步到
github:
https://github.com/CocaineCong/TeenStudy
gitee:
https://gitee.com/cocainecong/TeenStudy
import requests
from email.mime.text 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.com','张三'], [ '22222@qq.com','李四'],
[ '333333@qq.com','老王'], ['444444@qq.com', '小王'], # TODO 这里记得要改
]
def GetCookie(username, password):
try:
url = 'http://m.fjcyl.com/login'
chrome_path = r"D:\Download\Dirver\chromedriver_win32\chromedriver.exe"
# TODO 驱动的路径,记得换成你的驱动
driver = webdriver.Chrome(executable_path=chrome_path)
driver.get(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)
# 获取验证码位置,自动定位不是很明白,就使用了手动定位,代表(左,上,右,下)
ran.crop(box).save("./TempImage/02.png") # 把获取的验证码保存
# 获取验证码图片,读取验证码
imageCode = Image.open("./TempImage/02.png") # 打开保存的验证码图片
sharp_img = ImageEnhance.Contrast(imageCode).enhance(2.0) # 图像增强,二值化
sharp_img.save("./TempImage/03.png") # 保存图像增强,二值化之后的验证码图片
sharp_img.load() # 对比度增强
img = Image.open('./TempImage/03.png')
img = img.convert('RGB') # 这里也可以尝试使用L
enhancer = ImageEnhance.Color(img)
enhancer = enhancer.enhance(0)
enhancer = ImageEnhance.Brightness(enhancer)
enhancer = enhancer.enhance(2)
enhancer = ImageEnhance.Contrast(enhancer)
enhancer = enhancer.enhance(8)
enhancer = ImageEnhance.Sharpness(enhancer)
img = enhancer.enhance(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")
driver.execute_script("arguments[0].click();", element1)
dictCookies = driver.get_cookies() # 获取cookie
sleep(2)
driver.close()
return dictCookies[0]["value"]
except Exception as err:
return "500"
# 请求头
headers = {
'Host': 'm.fjcyl.com',
'Referer': 'http://m.fjcyl.com/',
'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 = "http://m.fjcyl.com/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 = "http://m.fjcyl.com/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是日期
num = LastestNum()
URL = "http://m.fjcyl.com/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 = "http://m.fjcyl.com/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("全部都完成了")
return 0
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.com' # 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()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
会有不足,希望大佬斧正!
文章来源: blog.csdn.net,作者:小生凡一,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_45304503/article/details/114501006
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)