python自动发微信-python实现微信每日一句自动发送给喜欢的人
本文實(shí)例為大家分享了python實(shí)現(xiàn)微信每日一句自動(dòng)發(fā)送的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
# -*- coding: utf-8 -*-
"""
這是一個(gè)用來(lái)測(cè)試微信自動(dòng)發(fā)送消息的demo
恩,主要就是用到了一個(gè)微信庫(kù)--wxpy
安裝很簡(jiǎn)單 pip install wxpy
下面就開始吧
主要就兩個(gè)函數(shù)
1、getNews();用以獲取信息
2、sendNews();用以發(fā)送信息
我這里發(fā)送消息用的是for循環(huán)本意是群發(fā),但是!但是!但是!程序發(fā)的太快會(huì)被微信禁掉,大概40個(gè)人左右就會(huì)被禁,以后可以試試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("發(fā)送給 "+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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
總結(jié)
以上是生活随笔為你收集整理的python自动发微信-python实现微信每日一句自动发送给喜欢的人的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 初次联系导师短信模板_2020考研复试:
- 下一篇: python snmp采集交换机信息_P