python实现微信自动发信息软件_python实现微信每日一句自动发送给喜欢的人
本文實例為大家分享了python實現微信每日一句自動發送的具體代碼,供大家參考,具體內容如下
參考了一篇博客:教你使用python實現微信每天給女朋友說晚安
代碼:
# -*- coding: utf-8 -*-
'''
這是一個用來測試微信自動發送消息的demo
恩,主要就是用到了一個微信庫--wxpy
安裝很簡單 pip install wxpy
下面就開始吧
主要就兩個函數
1、getNews();用以獲取信息
2、sendNews();用以發送信息
我這里發送消息用的是for循環本意是群發,但是!但是!但是!程序發的太快會被微信禁掉,大概40個人左右就會被禁,以后可以試試sleep一下。
另外vscode中自定義python編譯器:
Ctrl+shift+p, 選擇 python: Select Interpreter
'''
from __future__ import unicode_literals
from wxpy import *
import requests
from threading import Timer
itchat = Bot(console_qr=2,cache_path="botoo.pkl")
def getNews():
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
content = r.json()['content']
note = r.json()['note']
return content, note
def sendNews():
try:
#這里是備注
friend = itchat.friends().search(name = u'xxx')
content = getNews()
print(content)
message1 = str(content[0])
message2 = str(content[1])
message3 = "xxx"
print(friend)
for index,item in enumerate(friend):
print("發送給 "+str(item)+" ing,index="+str(index))
item.send(message1)
item.send(message2)
item.send(message3)
t = Timer(86400,sendNews)
t.start()
except:
errorMessage = "xxx"
for index,item in enumerate(friend):
item.send(errorMessage)
if __name__ == "__main__":
sendNews()
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。
本文標題: python實現微信每日一句自動發送給喜歡的人
本文地址: http://www.cppcns.com/jiaoben/python/258044.html
總結
以上是生活随笔為你收集整理的python实现微信自动发信息软件_python实现微信每日一句自动发送给喜欢的人的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 打印某个进程下的所有线程--Linux环
- 下一篇: Spring+Spring Securi