利用Python向微信好友发消息

白俊遥博客

所需要的库

pip install wxpy

pip install requests


白俊遥博客

#!/usr/bin/python
# -*- coding:utf-8 -*-

from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests

bot = Bot()


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


def send_news():
    try:
        my_friend = bot.friends().search(u'微信名称')[0]  # 你朋友的微信名称,不是备注,也不是微信账号
        my_friend.send(get_news()[0])
        my_friend.send(get_news()[1][5:])
        my_friend.send(u"来自爸爸的心灵鸡汤!")
    except:
        my_friend = bot.friends().search(u'微信名称')[0]
        my_friend.send(u"今天消息发送失败了")


if __name__ == "__main__":
    send_news()


打赏,支持一下

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

Powered by WEIXIA.XIN,学的不仅是技术,更是梦想!!!

Davidvivi博客
请先登录后发表评论
  • 最新评论
  • 总共 0条评论