python乱れ操作、微信の友達を指定してメッセージを送ります.

1011 ワード

友達を指定してメッセージを送ります.
  • みんなはテストの時できるだけWeChatトランペットを使います.
  • コードを変えずにテストしないでください.
  • ここで金山詞覇の毎日一句を呼び出しました.文字情報を指定して送ることもできます.七夕がもうすぐ来ます.分かります.
  • 
    from threading import Timer
    from wxpy import *
    import requests
    
    bot = Bot()#    ,             
    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(u'  ')[0]#           
            my_friend.send(contents[0])
            my_friend.send(contents[1])
            my_friend.send(u'      ')
            t = Timer(86400,send_news)#         ,86400s = 24h
    
            t.start()
    
        except:
            my_friend = bot.friends().search('sixkery')[0]#         
            my_friend.send(u'         ')
    
    if __name__ == '__main__':
        send_news()