1 Star 1 Fork 1

vencol/pywechat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo_guiwin32.py 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
vencol 提交于 2024-03-29 16:43 . 通过win32把图片放入剪切板
import os,time,random
import pyautogui
import pyperclip
from io import BytesIO
from PIL import Image
# import win32clipboard as clb
# import pywin32clipboard
from win32 import win32clipboard as clb
from wechatdata import data_prase as wdp
# import win32gui
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
def search_by_name(name) :
pyautogui.hotkey('ctrl', 'f')
pyperclip.copy(name)
pyautogui.hotkey('ctrl', 'v')
time.sleep(0.5) # 要有0.5s才反应正常
pyautogui.press('enter')
def send_message(msg) :
pyperclip.copy(msg)
pyautogui.hotkey('ctrl', 'v')
pyautogui.press('enter')
def send_msg_list(msglist) :
for onemsg in msglist:
print(onemsg)
time.sleep(random.uniform(0.2, 1))
send_message(onemsg)
def send_text_message(name, msglist) :
search_by_name(name)
send_msg_list(msglist)
time.sleep(0.3)
def copy_image_to_clip(imagepath) :
if not os.path.exists(imagepath) :
return
image = Image.open(imagepath)
# 声明output字节对象
output = BytesIO()
# 用BMP (Bitmap) 格式存储
# 这里是位图,然后用output字节对象来存储
image.save(output, 'BMP')
# BMP图片有14字节的header,需要额外去除
data = output.getvalue()[14:]
# 关闭
output.close()
clb.OpenClipboard()
clb.EmptyClipboard()
clb.SetClipboardData(clb.CF_DIB, data)
clb.CloseClipboard()
time.sleep(1)
def send_image_message(name, imagepath) :
if not os.path.exists(imagepath) :
return
search_by_name(name)
copy_image_to_clip(imagepath)
pyautogui.hotkey('ctrl', 'v')
time.sleep(random.uniform(0.5, 2))
pyautogui.press('enter')
def send_at_by_hotkey(name) :
pyautogui.hotkey('shift', '2')
pyperclip.copy(name)
pyautogui.hotkey('ctrl', 'v')
time.sleep(0.1)
def main():
configdata = wdp.read_data_from_csv('wedata.csv')
optlen = len(configdata)
print(optlen)
# return
pyautogui.hotkey('ctrl', 'alt', 'w')
for one in configdata:
name, (txttype, txt), (imgtype, img), (attype, atone) = one
print(name)
if txttype != True:
print(txt)
send_text_message(name, txt)
if imgtype != True:
print(img)
send_image_message(name, img)
if attype != True:
print(atone)
# send_image_message('123.png')
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
os._exit(1)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vencol/pywechat.git
git@gitee.com:vencol/pywechat.git
vencol
pywechat
pywechat
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385