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自动发微信-python实现微信每日一句自动发送给喜欢的人的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 初次联系导师短信模板_2020考研复试:
- 下一篇: boAt Wave Armour 坚固型