微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用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.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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐