如何给自己的微信好友发送金山词霸每日一词

   日期:2020-11-09     浏览:103    评论:0    
核心提示:需要下载的package打开微信,打开要发送的好友聊天窗口即可。# -*- coding: utf-8 -*-# @Time : 2020/11/8 21:33# @Author : AWAYASAWAY# @File : 1.py# @IDE : PyCharmimport win32guiimport win32apiimport win32conimport timeimport randomimport requestsfrom threadi

需要下载的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()

如需对本代码进行修改和改进,建议先对文件助手发送。否则后果自负。

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服