需要下載的package



打開微信,打開要發送的好友聊天視窗即可,
# -*- coding: utf-8 -*-
# @Time : 2020/11/8 21:33
# @Author : AWAYASAWAY
# @File : 1.py
# @IDE : PyCharm
import win32gui
import win32api
import win32con
import time
import requests
from threading import Timer
import win32clipboard as w
def get_news():
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36 Edg/86.0.622.63'
}
url = 'http://open.iciba.com/dsapi'
response = requests.get(url, headers=headers)
content = response.json()['content']
note = response.json()['note']
return content, note
def getClipBoardText():
w.OpenClipboard()
d = w.GetClipboardData(win32con.CF_TEXT)
w.CloseClipboard()
return d
def setClipBoardText(data):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardText(data)
w.CloseClipboard()
def ctrlV():
win32api.keybd_event(17, 0, 0, 0) # ctrl鍵位碼是17
win32api.keybd_event(86, 0, 0, 0) # v鍵位碼是86
win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0) # 釋放按鍵
win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)
def altS():
win32api.keybd_event(18, 0, 0, 0) # Alt鍵位碼
win32api.keybd_event(83, 0, 0, 0) # s鍵位碼
win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0) # 釋放按鍵
win32api.keybd_event(83, 0, win32con.KEYEVENTF_KEYUP, 0)
weixin = win32gui.FindWindow(None, "微信")
win32gui.SetForegroundWindow(weixin)
left, top, right, bottom = win32gui.GetWindowRect(weixin)
print(left, top, right, bottom)
def send_news():
contents = get_news()
theWordYouWantToSay = contents
# for i in range(0, 2):
click_x = 732 - 423 + left + 80
# click_x 和clilck_y點到輸入框
click_y = bottom - (918 - 775) + 60
win32api.SetCursorPos([click_x, click_y])
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP | win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
setClipBoardText(u'Hello, Miao~miao' + '\n' + theWordYouWantToSay[0] + '\n' + theWordYouWantToSay[1]) # 自行修改好友名字
ctrlV()
win32api.keybd_event(13, 0, 0, 0) # 13 enter
win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0)
time.sleep(0.5)
# t = Timer(86400, send_news) # 24h
# t = Timer(3, send_news) # 3s 設定每時間發送,不建議,親測會被好友洗掉
# t.start()
if __name__ == '__main__':
# send_news()
# 設定最大運行次數,防止被刪好友
runNums = 3
for i in range(runNums):
send_news()
如需對本代碼進行修改和改進,建議先對檔案助手發送,否則后果自負,


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/209991.html
標籤:其他
上一篇:NumPy全基礎學習
下一篇:主板接喇叭沒有聲音
