代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。