2019-01-12-python實(shí)現(xiàn)微信每日一句自動(dòng)發(fā)送

# -*- coding: utf-8 -*-

'''

博客地址:http://www.cnblogs.com/botoo/p/8622379.html

微信庫--wxpy? 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()

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容