Learn practical skills, build real-world projects, and advance your career
Created 5 years ago
from wxpy import *
bot = Bot()
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as 🕷
# 注册好友请求类消息
@bot.register()
def auto_accept_friends(msg):
# if '功能' in msg.text.lower():# 判断好友请求中的验证文本
new_friend = bot.accept_friend(msg.card) # msg.card 为该请求的用户对象
# 或 new_friend = msg.card.accept()
new_friend.send('[坏笑]你好,我是微信助手!')
# 群信息同步
def update_group(keys=['闲聊']):
groups = []
for key in keys:
groups += bot.groups(True).search(key)
for group in groups:
group.update_group(True)
return groups
groups = update_group(['夸夸', '拼车'])
groups_forword = groups
@bot.register(groups) # 自动接受验证信息中包含 'wxpy' 的好友请求
def groups_synchronize(msg):
prefix = '来自 %s 的 %s\n%s\n' % (msg.sender.name, msg.member.name, '-' * 32)
# sync_message_in_groups(msg, gs[:1], prefix) # 单向转发
sync_message_in_groups(msg, groups_forword, prefix)
#群聊管理
@bot.register(my_group, msg_types=TEXT)
def group(msg):
if msg.is_at :
if '踢出' in msg.text:
if msg.member == group_admin :
for member_name in msg.text.split('@')[2:]:
print(member_name)
re_name = my_group.members.search(member_name)[0].remove()
print(re_name)
msg.sender.send("已经移出:"+member_name)
else:
return "你不是管理员不能进行踢人操作"
else:
xiaoi.do_reply(msg)
# tuling
@bot.register()
def tuling(msg):
tl = Tuling('3ac26126997942458c0d93de30d52212')
return tl.do_reply(msg)
# 功能
import pandas as pd
def get(idx, url='http://web.algo.browser.miui.srv/data/feed/recall?q=topnews'):
_ = pd.read_html(url, encoding='utf-8')[0][1].tolist()[:idx]
return ':\n' + '\n\n'.join(_)
@bot.register()
def topnews(msg):
s = re.sub(r'\s', '', msg.text)
print(s)
if s.startswith('#'):
args = s[1:].split('#')
print(args)
if args[0] == 'topnews':
topn = int(args[1])
url='http://web.algo.browser.miui.srv/data/feed/recall?q=topnews'
_ = pd.read_html(url, encoding='utf-8')[0][1].tolist()[:topn]
print(_)
return '\n\n'.join(_)