码迷,mamicode.com
首页 > 微信 > 详细

使用python定时发送微信信息

时间:2019-09-19 16:15:15      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:col   nic   金山词霸   ati   imp   from   定时   心灵鸡汤   每日   

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

使用python定时发送微信信息

标签:col   nic   金山词霸   ati   imp   from   定时   心灵鸡汤   每日   

原文地址:https://www.cnblogs.com/heimaguangzhou/p/11550125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!