python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息,python,智给,定时,发消息...
#author_='zhi';
#date: 2020/6/20 0020 13:34
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import random
bot = Bot()
# linux執行登陸請調用下面的這句
# bot = Bot(console_qr=2,cache_path="botoo.pkl")
def get_news():
"""獲取金山詞霸每日一句,英文和翻譯"""
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
content = r.json()['content']
note = r.json()['note']
return content, note
def send_news():
try:
contents = get_news()
# 你朋友的微信名稱,不是備注,也不是微信帳號。
my_friend = bot.friends().search('小智')[0]
my_friend.send(contents[0])
my_friend.send(contents[1])
my_friend.send(u"晚安")
# 每86400秒(1天),發送1次
t = Timer(86400, send_news)
# 為了防止時間太固定,于是決定對其加上隨機數
ran_int = random.randint(0, 100)
t = Timer(86400 + ran_int, send_news)
t.start()
except:
# 你的微信名稱,不是微信帳號。
my_friend = bot.friends().search('小智哥')[0]
my_friend.send(u"今天消息發送失敗了")
if __name__ == "__main__":
send_news()
總結
以上是生活随笔為你收集整理的python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息,python,智给,定时,发消息...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python读文本文件的过程是怎样的_读
- 下一篇: python离散余弦变换_在python