Пример #1
0
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 16 08:22:17 2018

@author: Administrator
"""

# -*- coding: utf-8 -*-
"""
微信好友性别及位置信息
"""

#导入模块
from wxpy import Bot
'''Q
微信机器人登录有3种模式,
(1)极简模式:robot = Bot()
(2)终端模式:robot = Bot(console_qr=True)
(3)缓存模式(可保持登录状态):robot = Bot(cache_path=True)
'''
#初始化机器人,选择缓存模式(扫码)登录
robot = Bot(cache_path=True)

#获取好友
robot.chats()
#robot.mps()#获取微信公众号信息

#获取好友的统计信息
Friends = robot.friends()
print(Friends.stats_text())
Пример #2
0
    return 'received: {} ({})'.format(msg.text, msg.type)


# 打印出所有群聊中@自己的文本消息,并自动回复相同内容
# 这条注册消息是我们构建群聊机器人的基础
@bot.register(Group, TEXT)
def print_group_msg(msg):
    if msg.is_at:
        print(msg)
        msg.reply(msg.text)


# 获取所有类型的消息(好友消息、群聊、公众号,不包括任何自己发送的消息)
# 并将获得的消息打印到控制台
@bot.register()
def print_others(msg):
    print(msg)


# 通过机器人对象 Bot 的 chats(), friends(),groups(), mps() 方法, 可分别获取到当前机器人的 所有聊天对象、好友、群聊,以及公众号列表。
bot.chats()
bot.friends()
bot.groups()
bot.mps()

# 堵塞线程 进入Python 命令行 让程序保持运行
embed()

# 或者仅仅堵塞线程
# bot.join()