python 给微信好友发消息

发送搞定了,接收没搞定,有时间再搞

#pip install wxpy

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

#机器人
bot = Bot()

def get_news():
    url = "http://open.cicba.com/dsapi/"
    r = requests.get(url)
    content = r.json()['content']
    note = r.json()['note']
    return content,note

def send_news(str):
    try:
        #contents = [2,2,3]
        #好友列表  备注显示
        #print(bot.friends())
        print(bot.friends().search(u'木头人'))
        # 微信昵称,不是账号
        #my_friend = bot.friends().search(u'莫')[0]
        #发送
        #my_friend.send(contents[0])
        #发送图片
        #my_friend.send_image("C:\\Users\\Administrator.000\\Desktop\\intiloading.png")
        # 发送视频
        #my_friend.send_video('my_video.mov')
        # 发送文件
        #my_friend.send_file('my_file.zip')
        # 以动态的方式发送图片   没啥用
        # my_friend.send('@img@C:\\Users\\Administrator.000\\Desktop\\intiloading.png')
        # t = Timer(86400,send_news("kaishi"))
        # t.start()

        print(bot.groups)#<bound method Bot.groups of <Bot: 灵魂攻城狮>>
        #bot对象里含有chats,friends,groups,mps等方法,分别可以获取当前机器人的聊天对象、好友、群聊、公众号等信息
        all_group = bot.groups()
        print("type all:",type(all_group))
        print(all_group)  #[<Group: 兑换狂人软件开发内部交流群>, <Group: 自足智能科技,百事通>]
        for i in all_group:
            Group = str(i)
            group = Group.replace("<Group: ","").replace(">","")
            #send=bot.groups().search(group)[0].send_image("1.jpg")
            print(Group)
            print(group)
            # print(send)

        #不能发给自己会报错
        # my = bot.friends().search(u'灵魂攻城狮')[0]
        # my.send("发送")
    except :
        my = bot.friends().search(u'灵魂攻城狮')[0]
        my.send("发送失败了")

if __name__ == '__main__':
    # str = input("输入q退出")
    # if str == "q":
    #     exit(0)
    # else:
    send_news(str)

    #sys.exit()






  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值