加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

使用python定时发送微信信息

发布时间:2020-12-20 10:40:00 所属栏目:Python 来源:网络整理
导读:from? __future__? import? unicode_literals from? threading? import? Timer from? wxpy? import? * import? requests bot = Bot() def? get_data(): ? ?? # 金山词霸每日一句,英文和翻译 ? ?? url =? "http://open.iciba.com/dsapi/" ? ?? r = requests.

from?__future__?import?unicode_literals
from?threading?import?Timer
from?wxpy?import?*
import?requests
bot = Bot()

def?get_data():
? ??# 金山词霸每日一句,英文和翻译
? ??url =?"http://open.iciba.com/dsapi/"
? ??r = requests.get(url)
? ? contents = r.json()[‘content‘]
? ? translation = r.json()[‘translation‘]

? ??return?contents,translation


def?send_data():
? ??try:
? ?? ???# 你朋友的微信名称。
? ?? ???my_friend = bot.friends().search(u‘Perdidas‘)[0]
? ?? ???#发送信息
? ?? ???my_friend.send(get_data()[0])
? ?? ???my_friend.send(get_data()[1][5:])
? ?? ???my_friend.send(u"--心灵鸡汤!")
? ?? ???# 每8秒,发送1次
? ?? ???t = Timer(8,send_data)
? ?? ???t.start()
? ??except:
? ?? ???# 你的微信名称。
? ?? ???my_friend = bot.friends().search(‘Perdidas‘)[0]

? ?? ???my_friend.send(u"消息发送失败了")

send_data()

更多技术咨询可关注:gzitcast

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读