序言
在家作息不规律,凌晨5点才睡,下午2点才醒,老是错过健康上报而被班委在群里面点名(挺不好意思的),然后参考李老的设计自己也动手写了一个自动健康上报的程序。
声明:
- 本程序是在本人健康的时候忘记健康上报而设计,若本人健康状态发生改变一定会取消程序运行,并且上报实情。
- 本程序只供本人使用,他人使用出现问题与本人无任何法律责任。
- 本程序设计思路是模仿人为动作进行点击,无任何侵犯行为。
代码如下
# -*-coding:utf-8 -*-
# 作者:不懂先生
# 日期: 2022/1/9
import time
import pyautogui
def health():
pyautogui.hotkey('win', 'd')
left1, top1, width1, height1 = pyautogui.locateOnScreen('weixin.png')
x1, y1 = pyautogui.center((left1, top1, width1, height1))
pyautogui.click(x1, y1)
left2, top2, width2, height2 = pyautogui.locateOnScreen('sousuo.png')
x2, y2 = pyautogui.center((left2, top2, width2, height2))
pyautogui.click(x2, y2)
if pyautogui.locateOnScreen('english.png'):
pyautogui.hotkey('shift')
pyautogui.typewrite('xinxihuabangongshi')
pyautogui.hotkey('space')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(1)
left4, top4, width4, height4 = pyautogui.locateOnScreen('xyk.png')
x4, y4 = pyautogui.center((left4, top4, width4, height4))
pyautogui.click(x4, y4)
time.sleep(2)
left5, top5, width5, height5 = pyautogui.locateOnScreen('jksb.png')
x5, y5 = pyautogui.center((left5, top5, width5, height5))
pyautogui.click(x5, y5)
time.sleep(1)
le,to,wid,hei = pyautogui.locateOnScreen('ok.png')
xx, yy = pyautogui.center((le, to, wid, hei))
pyautogui.click(xx, yy)
left9, top9, width9, height9 = pyautogui.locateOnScreen('tuichu1.png')
x9, y9 = pyautogui.center((left9, top9, width9, height9))
pyautogui.click(x9, y9)
time.sleep(2)
left6, top6, width6, height6 = pyautogui.locateOnScreen('sousuo1.png')
x6, y6 = pyautogui.center((left6, top6, width6, height6))
pyautogui.click(x6, y6)
if pyautogui.locateOnScreen('english.png'):
pyautogui.hotkey('shift')
pyautogui.typewrite('wenjianchuanshuzhushou')
pyautogui.hotkey('space')
time.sleep(1)
pyautogui.hotkey('enter')
time.sleep(1)
if pyautogui.locateOnScreen('chinese.png'):
pyautogui.hotkey('shift')
pyautogui.typewrite('yktwx.com')
pyautogui.hotkey('enter')
time.sleep(1)
left7, top7, width7, height7 = pyautogui.locateOnScreen('lj.png')
x7, y7 = pyautogui.center((left7, top7, width7, height7))
pyautogui.click(x7, y7)
time.sleep(1)
left8, top8, width8, height8 = pyautogui.locateOnScreen('tj.png')
x8, y8 = pyautogui.center((left8, top8, width8, height8))
pyautogui.click(x8, y8)
if (pyautogui.locateOnScreen('success.png')):
pyautogui.click(x9, y9)
left10, top10, width10, height10 = pyautogui.locateOnScreen('tuichu2.png')
x10, y10 = pyautogui.center((left10, top10, width10, height10))
pyautogui.click(x10, y10)
pyautogui.hotkey('win','d')
# 单独拉出来,防止出现一个选项得点多次才可
str = pyautogui.confirm(title="自动健康上报程序",text='请问是否开始自动健康上报',buttons=['现在上报','10分钟自动上报','今日不报'])
if str == '现在上报':
health()
elif str == '10分钟自动上报':
time.sleep(600)
health()
elif str == '今日不报':
exit()
成品图
2022/1/21日更新:添加了健康上报成功邮箱提示功能
邮箱模块代码如下:
import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def senmail(text_detail):
conn = smtplib.SMTP_SSL('smtp.163.com', 465) # 用SSL不会被识别为垃圾邮件,这里使用163邮箱
conn.login('发件人邮箱账号', '邮箱授权码')
msg = MIMEMultipart()
subject = Header('健康上报结果', 'utf-8').encode() # encode()使得邮件主题编码成二进制
msg['Subject'] = subject # 里面第一个字母得大写
msg['From'] = '邮箱账号 <邮箱账号>' # 发件人这里写完邮箱地址后还得再加一个空格再写<邮箱地址>
msg['To'] = '收件人邮箱' # 收件人这边不用再写<邮箱地址>
text = MIMEText(text_detail, 'plain', 'utf-8')
msg.attach(text)
conn.sendmail('发件人邮箱', '收件人邮箱账号', msg.as_string())
该函数加入到以下代码模块:
if (pyautogui.locateOnScreen('success.png')):
pyautogui.click(x9, y9)
left10, top10, width10, height10 = pyautogui.locateOnScreen('tuichu2.png')
x10, y10 = pyautogui.center((left10, top10, width10, height10))
pyautogui.click(x10, y10)
senmail('健康上报成功')
pyautogui.hotkey('win','d')
else :
senmail('健康上报失败,将重新启动健康上报程序')
health()
邮箱提示效果
解释
- 以上的
pyautogui.locateOnScreen('')
需要自己截图 - win计划执行可以参考win计划执行python程序
- pyautogui操作可以参考pyautogui
yktwx.com
该网页需要自己抓包并制作表单
`