程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Let the beloved TA no longer be lonely -- Python wechat chat robot

編輯:Python

Wechat chat robot

Realization principle

use itchat Log in wechat webpage , use schedule Send messages in a fixed period of time .
* notes : Wechat does not support web version , At present, this method cannot be used , There is no good solution . Possible ideas are direct use of stickers / Copy function and mouse / Keyboard control for information selection and transmission .

Code

import schedule
import time
import itchat
chatTarget = ' baby ' # Wechat user name sent to 
chatTime = '08:00' # Time to send messages 
chatMessage = ' Good morning, baby !' # Sent content 
itchat.auto_login() # Scan the code and log in web Version wechat , Restart the program to log in again 
def chat():
user = itchat.search_friends(name=chatTarget) # Search in the friends list 
itchat.send(chatMessage, user[0]['UserName']) # Send a message 
schedule.every().day.at(chatTime).do(chat) # Plan to send messages every day at the specified time 
while True:
schedule.run_pending() # Implementation plan 
time.sleep(10) # Refresh interval 

It looks like , While snoring, you can give your beloved in the early morning TA Send a greeting !

Functional expansion

schedule You can also book more complicated times , Such as the first half of the week in every month .
itchat You can also get user replies , Call Turing robot API It can really realize automation !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved