Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改了一个小bug同时添加了可选的邮件提示功能 #13

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/automate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

- name: run
run: STD_ID='${{ secrets.STD_ID }}' PASSWORD='${{ secrets.PASSWORD }}' python3 main.py
run: STD_ID='${{ secrets.STD_ID }}' PASSWORD='${{ secrets.PASSWORD }}' SENDER='${{ secrets.SENDER}}' SENDER_PWD='${{ secrets.SENDER_PWD}}' RECEIVER='${{ secrets.RECEIVER}}' python3 main.py
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

![](https://tva1.sinaimg.cn/large/008i3skNgy1gvtyc9lzodj30oy0l4tb5.jpg)

### 3.(可选)自动发送邮件进行报错
在登陆失败或前日未填写平安复旦而导致填写失败时会自动发送邮件进行提示

若要启动此功能,需要添加以下三项secrets

1. SENDER: 发件邮箱地址(仅支持复旦邮箱)
2. SENDER_PWD: 发件邮箱密码
3. RECEIVER: 收件邮箱地址(未填写则默认设为发件邮箱)

上述内容填写与否不影响正常功能的使用



Expand Down
48 changes: 46 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from PIL import Image
from PIL import ImageEnhance

import smtplib
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formataddr

from requests import session, post, adapters
import urllib3, ssl
adapters.DEFAULT_RETRIES = 5
Expand Down Expand Up @@ -126,6 +132,7 @@ def login(self):
"\n***********************\n")
else:
print("◉登录失败,请检查账号信息")
send_mail("登录失败,请检查账号信息")
self.close()

def logout(self):
Expand Down Expand Up @@ -178,6 +185,10 @@ def check(self):
time.tzset()
today = time.strftime("%Y%m%d", time.localtime())
print("◉今日日期为:", today)
if last_info["d"]["info"]== False:
print("\n***昨日未填写,今日请手动填写***")
send_mail("昨日未填写,今日请手动填写")
self.close()
if last_info["d"]["info"]["date"] == today:
print("\n*******今日已提交*******")
self.close()
Expand Down Expand Up @@ -268,13 +279,15 @@ def checkin(self):
time.sleep(0.1)
if(json_loads(save.text)["e"] != 1):
break


def get_account():
"""
获取账号信息
"""
uid = getenv("STD_ID")
psw = getenv("PASSWORD")

if uid != None and psw != None:
print("从环境变量中获取了用户名和密码!")
return uid, psw
Expand Down Expand Up @@ -302,9 +315,40 @@ def get_account():
return uid, psw


def send_mail(txt):
def mail(txt):
ret = True
try:
sender = getenv("SENDER")
sender_pwd = getenv("SENDER_PWD")
receiver = getenv("RECEIVER")
if receiver == '':
receiver = sender

print(sender,sender_pwd,receiver)

#创建一个带附件的实例
message = MIMEMultipart()
message['From'] = Header("pafd_aiutomated", 'utf-8')
message['To'] = Header("user", 'utf-8')
message['Subject'] = Header(txt, 'utf-8')

server = smtplib.SMTP_SSL("mail.fudan.edu.cn", 465) # 发件人邮箱中的SMTP服务器,端口是25
server.login(sender, sender_pwd) # 括号中对应的是发件人邮箱账号、邮箱密码
server.sendmail(sender, [receiver, ], message.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
server.quit() # 关闭连接
except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False
ret = False
return ret
ret = mail(txt)
if ret:
print("邮件发送成功")
else:
print("邮件发送失败")

if __name__ == '__main__':
uid, psw = get_account()
# print(uid, psw)
uid, psw= get_account()

zlapp_login = 'https://uis.fudan.edu.cn/authserver/login?' \
'service=https://zlapp.fudan.edu.cn/site/ncov/fudanDaily'
code_url = "https://zlapp.fudan.edu.cn/backend/default/code"
Expand Down