用python实现微信定时发送图片

用电脑微信实现定时给好友发送多张图片

一、需要安装的库:

apscheduler
os
pyautogui
pyperclip
time
PIL
win32clipboard,win32con

二、定义几个函数

(1)

def send():#发送图片的函数
    # 复制需要发送的内容到粘贴板
    # 模拟键盘 ctrl + v 粘贴内容
    pyautogui.hotkey('ctrl', 'v')
    # 发送消息
    pyautogui.press('enter')

(2)

def serch_friend(friend):
    # Ctrl + alt + w 打开微信
    pyautogui.hotkey('ctrl', 'alt', 'w')
    # 搜索好友
    pyautogui.hotkey('ctrl', 'f')
    # 复制好友昵称到粘贴板
    pyperclip.copy(friend)
    # 模拟键盘 ctrl + v 粘贴
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(1)
    # 回车进入好友消息界面
    pyautogui.press('enter')
    get_img()

(3)

def get_img():
    imagepath = "D:/xunlei/pic"  # 自己的图片文件夹路径
    all = os.walk(imagepath)
    i = 0
    for path, dir, file_list in all:  # 遍历图片
        print(path, dir, file_list)

        for filename in file_list:
            if filename.endswith('.jpg') or filename.endswith('.png'):
                clip.OpenClipboard()  # 打开剪贴板
                clip.EmptyClipboard()  # 先清空剪贴板
                image = os.path.join(imagepath, path, filename)
                print(image)

                img = Image.open(image)
                output = BytesIO()
                img.convert("RGB").save(output, "BMP")
                data = output.getvalue()[14:]
                output.close()
                clip.SetClipboardData(win32con.CF_DIB, data)  # 将图片放入剪贴板
                clip.CloseClipboard()
                time.sleep(1)
                send()
                i += 1
                if i > 5:  # 想发送 n 张就设置 i > n-1(3 为发送的最大数量-1 i从0开始 所以设置为3,是4张图片:  0 1 2 3)
                    print('发送完成')
                    return 0

(4)


```python
def send_message():
    friend_name = "文件传输助手"#要发送的好友名字

    serch_friend(friend_name)

三、进行定时设计

#利用apscheduler模块实现定时发送,运行send_message主函数
if __name__ == '__main__':

    # 设置时域
    scheduler = BlockingScheduler(timezone="Asia/Shanghai")
    # 时间设置,每年的10月,每天的8-11,2-4点半,
    scheduler.add_job(send_message, 'cron', month='10', hour='8-11,2-4', minute='30')
    # 定时语言
    try:
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        pass

参考的文献:[微信发送图片](https://blog.csdn.net/q1246192888/article/details/123954908?ops_request_misc=&request_id=&biz_id=102&utm_term=%E5%BE%AE%E4%BF%A1%E5%AE%9A%E6%97%B6%E4%BC%A0%E9%80%81%E5%9B%BE%E7%89%87&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-123954908.142%5Ev56%5Epc_rank_34_queryrelevant25,201%5Ev3%5Econtrol_2&spm=1018.2226.3001.4187)
  • 1
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值