美文网首页
微信定时给某人发消息

微信定时给某人发消息

作者: 朝畫夕拾 | 来源:发表于2019-08-09 09:35 被阅读0次

    from  __future__  import  unicode_literals

    from  threading   import  Timer

    import  requests

    from  wxpy   import   *  # 导入模块

    # 初始化机器人,扫码登陆

    bot= Bot()

    # 搜索名称含有 "xxx"这里是自己的微信昵称

    # my_friend = bot.friends().search('如水', sex=FEMALE, city="上海")[0]

    #bot = None

    def get_news():    #获取金山词霸每日一句,英文和翻译

        url= "http://open.iciba.com/dsapi/"

        r= requests.get(url)

        #print(r.json())

        content= r.json()['content']

        note= r.json()['note']

        translation= r.json()['translation']

        return content, note, translation

    def login_wechat():

        global bot

    bot= Bot()

        #bot = Bot(console_qr=2, cache_path="botoo.pkl")# linux执行登陆时,调用

    def send_news():

        if bot== None:

            login_wechat()

        try:

            contents= get_news()

            # 你朋友的微信备注,请注意最好你的好友备注只有1个

            my_friend= bot.friends().search(u'如水')[0]

            my_friend.send(contents[0])

            my_friend.send(contents[1])

            my_friend.send(get_news()[2][5:])

            my_friend.send(u"Have a good one,照顾好自己!")

            t= Timer(86400, send_news)        # 每86400秒(1天),发送1次

            t.start()

        except:

            print(u"失败!!")          # 你的好友微信名称,不是微信帐号

            my_friend= bot.friends().search('如水')[0]

            my_friend.send(u"今天消息发送失败了!!")

    if __name__== "__main__":

        send_news()

        print(get_news()[0])

    相关文章

      网友评论

          本文标题:微信定时给某人发消息

          本文链接:https://www.haomeiwen.com/subject/juccjctx.html