-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
52 lines (44 loc) · 1.48 KB
/
utils.py
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
import ddddocr
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
import settings
def get_captcha(img_path):
# 创建一个ddddocr对象
ocr = ddddocr.DdddOcr(show_ad=False)
# 读取验证码图片的字节数据
with open(img_path, 'rb') as f:
img_bytes = f.read()
# 使用ddddocr进行验证码识别
result = ocr.classification(img_bytes).upper()
# 返回识别结果
return result
def send_email(subject,message):
message = MIMEText(message, 'plain', 'utf-8')
message['From'] = formataddr((settings.mail_title, settings.mail_user))
message['To'] = formataddr(("管理员", settings.mail_targets[0]))
message['Subject'] = Header(subject, 'utf-8')
for i in range(3):
try:
smtpObj = smtplib.SMTP(settings.mail_host, 25,timeout=5)
# smtpObj.starttls()
smtpObj.login(settings.mail_user,settings.mail_pass)
smtpObj.sendmail(settings.mail_user, settings.mail_targets, message.as_string())
print("邮件发送成功")
return True
except Exception as e:
print(e)
print("Error: 无法发送邮件")
return False
def check_update(last,data):
updates=[]
for i in data:
t=False
for j in last:
if i["course"] == j["course"]:
t=True
break
if not t:
updates.append(i)
return updates