#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import requests
import wxpy
name_url_list = []
def get_url():
"""监听微信群获取url"""
bot = wxpy.Bot(cache_path=True)
company_group = bot.groups().search('py9录音小组5')[0]
@bot.register(chats=company_group) # 接收从指定群发来的消息,发送者即recv_msg.sender为组
def recv_send_msg(recv_msg):
name = recv_msg.member
url = recv_msg.text
print(f'{name} send {url}')
name_url_list.append((name, url))
wxpy.embed()
def save_mp3(name, url):
"""保存MP3"""
response = requests.get(url)
data = response.text
mp3_url = re.findall('"playurl":"(.*?)"', data)
mp3_response = requests.get(mp3_url[0])
mp3_data = mp3_response.content
with open(f'{name}.mp3', 'wb') as fw:
fw.write(mp3_data)
if __name__ == '__main__':
get_url()
for name, url in name_url_list:
save_mp3(name, url)