Skip to content

Instantly share code, notes, and snippets.

@Bluefissure
Last active June 19, 2020 15:11
Show Gist options
  • Save Bluefissure/d7fa91e9dd511df6e7c5869b8c2510dd to your computer and use it in GitHub Desktop.
Save Bluefissure/d7fa91e9dd511df6e7c5869b8c2510dd to your computer and use it in GitHub Desktop.
import pyautogui
import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
import requests
import base64,json
from io import BytesIO
import os
MAIL_HOST="smtp.qq.com"
MAIL_USER="123456789@qq.com"
MAIL_PASS="123456789password"
BAIDU_ACCESS_TOKEN = ""
BAIDU_OCR_URL = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token='+BAIDU_ACCESS_TOKEN
MY_NAME = "角色名"
def detect_owner(img):
output_buffer = BytesIO()
img.save(output_buffer, format='JPEG')
byte_data = output_buffer.getvalue()
base64_str = base64.b64encode(byte_data)
data = {
"image":base64_str
}
r = requests.post(url=BAIDU_OCR_URL,data=data)
print(r.text)
json_res = json.loads(r.text)
cnt = 0
name = ""
for item in json_res["words_result"]:
cnt += 1
if(cnt>1):
name+=","
print("%s %s"%(cnt,item["words"]))
name += item["words"]
return name
def send_mail(owner_img):
sender = MAIL_USER
receivers = [MAIL_USER]
nowtime = time.time()
try:
owner = detect_owner(owner_img)
for receiver in receivers:
nowtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(nowtime))
message = "土地竞拍结束于%s,房主为%s,自动退出。"%(nowtime,owner)
print(message)
msg=MIMEText(message,'plain','utf-8')
msg['From']=formataddr(["土地竞拍结束",MAIL_USER])
msg['To']=formataddr(["User",receiver])
msg['Subject']="土地竞拍结束"
if(owner == MY_NAME):
msg['Subject']+="(卧槽蹲到了)"
else:
msg['Subject']+="(遗憾没蹲到)"
server=smtplib.SMTP_SSL(MAIL_HOST, 465)
server.login(MAIL_USER, MAIL_PASS)
server.sendmail(MAIL_USER,[receiver,],msg.as_string())
server.quit()
print("Mail success")
time.sleep(10)
except Exception as e:
print(e)
print("Mail error")
if __name__=='__main__':
time.sleep(5)
fir = True
while(1):
time.sleep(1)
nowtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
print(nowtime)
pyautogui.typewrite(['num0', 'num0'], interval=0.2)
if fir:
pyautogui.typewrite(['num0'], interval=0.2)
fir = False
#time.sleep(0.2)
#jingpai = pyautogui.locateOnScreen('tudijingpai.png')
fangzhu = pyautogui.locateOnScreen('fangzhu.png')
if (fangzhu):
print("土地竞拍结束,自动退出。")
owner_img = pyautogui.screenshot().crop((717, 460, 813, 482))
send_mail(owner_img)
pyautogui.typewrite(['esc'], interval=2)
break
pyautogui.typewrite(['num0', 'num0', 'num4', 'num0'], interval=0.2)
time.sleep(2)
pyautogui.typewrite(['9', 'num4', 'num0'], interval=2)
#os.system("shutdown -s -t 60")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment