纯自动化的消息发送工具实现!
生活随笔
收集整理的這篇文章主要介紹了
纯自动化的消息发送工具实现!
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
純自動化的python實現(xiàn)模仿的是人的手動操作的過程,并不做后端接口等的實際操作。
通過模仿手動操作完成業(yè)務處理,這里使用到了兩個python的非標準模塊,分別是pyautogui和pyperclip模塊。
如果沒有安裝的話直接使用pip的方式安裝一下這兩個模塊。
pip install pyperclip -i https://pypi.tuna.tsinghua.edu.cn/simplepip install pyautogui -i https://pypi.tuna.tsinghua.edu.cn/simple安裝過程沒有其他比較曲折的操作,安裝完成后將我們需要的模塊導入到代碼塊中即可。
# Importing the pyautogui module and renaming it to gui. import pyautogui as gui# Importing the pyperclip module and renaming it to clip. import pyperclip as clip# Importing the time module and renaming it to t. import time as t本文代碼塊中的部分注釋是使用AI插件自動生成的,省去了我開發(fā)代碼塊時編寫注釋的過程。
由于實現(xiàn)過程比較簡單這里并沒有編寫對象類,直接在.py的文件中創(chuàng)建一個send_message()函數(shù)。
def send_message(fri_name=None, msgs=None):"""This function sends a message to a friend.:param fri_name: The name of the friend you want to send the message to:param msgs: The message you want to send"""gui.hotkey('ctrl', 'alt', 'w')gui.hotkey('ctrl', 'f')gui.copy(fri_name)gui.hotkey('ctrl', 'v')t.sleep(0.5)gui.press('enter')# 通過使用一系列的快捷鍵的操作,這個時候需要發(fā)消息的用戶聊天窗口已經(jīng)打開了for msg in msgs:clip.copy(msg)clip.hotkey('ctrl', 'v')clip.press('enter')t.sleep(1)這個時候通過一系列的模仿手動打開微信和復制粘貼的動作以及使用enter鍵發(fā)送消息等,一系列動作就操作完了。
因為ctrl+alt+w的快捷鍵是打開微信,我們也可以替換成打開其他應用的快捷鍵,比如說QQ等。
最后,只需要傳入朋友昵稱參數(shù)和需要發(fā)送的消息列表就能實現(xiàn)自動化發(fā)消息的操作了。
send_message(fri_name='張三', msgs=['消息1', '消息2', '消息3', '消息4', '消息5', '消息6', '消息7'])往期精彩
介紹幾個常用的搜索引擎語法,查找資料如虎添翼!
手撕一個圖片色卡提取器,可自定義提取色卡數(shù)量!
數(shù)據(jù)可視化:四種關系圖數(shù)據(jù)可視化的效果對比!
總結
以上是生活随笔為你收集整理的纯自动化的消息发送工具实现!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021年陕西商洛高考成绩查询,2021
- 下一篇: Type-C小家电,将传统小家电的接口从