当前位置:网站首页>Set up a QQ robot for ordering songs, and watch beautiful women

Set up a QQ robot for ordering songs, and watch beautiful women

2022-06-23 10:22:00 Skin kid LS

Preface

The complete project includes the framework 、 The code and detailed instructions can be downloaded from the link :
QQ Robot Basic Edition ( article 1-2 All functions )
QQ Robot multifunction version ( article 1-3 All functions )

After downloading, you only need to modify several places according to the instructions to build successfully !!

First article :QQ Robot detailed production tutorial ( From configuration to simple functions )
The second article : Building a QQ The robot chats with her girlfriend and wakes her up

The first two articles are on CSDN Comprehensive hot list , First of all Thanks for the official recommendation , Secondly, we need Thank you for your support ! I will continue to work hard ! We also look forward to your comments on this article One key, three links Oh . Please add a picture description

This article adds the function of the robot , It is mainly realized through some interesting interfaces , Here are some screenshots :
 Please add a picture description
 Please add a picture description

 Please add a picture description
 Please add a picture description
To achieve the above functions are based on the first article , So if you haven't read the first article, go and have a look first .
First article :QQ Robot detailed production tutorial ( From configuration to simple functions )

Concrete realization

1、 Burst light

When people call our robot shots , What do I do ? Certainly. , Direct flash .
You can refer to Help document
 Insert picture description here

if ' Burst light ' in message:
                qq = rev['sender']['user_id']
                send_msg({
    'msg_type': 'private', 'number': qq, 'msg': '[CQ:image,file={},type=flash,id=40004]'.format('https://c-ssl.duitang.com/uploads/blog/202012/16/20201216083017_6103b.thumb.1000_0.jpg')})

This picture address needs a network address , You can find one online .

I wrote a random picture function myself , You can refer to it .
website :https://www.duitang.com/search/?kw= beauty &type=feed( Of course, you can change the key words kw)
 Insert picture description here
f12 Enter developer mode , Continue to slide down to load more pictures , You can see that there is an interface , There are several parameters .
 Insert picture description here
python Code :

import json, requests
from bs4 import BeautifulSoup
import random

img_list = []
def get_img_random():
    for j in [0,24,48,72]:
        #  Get website data 
        url = requests.get('https://www.duitang.com/search/?kw= beauty &type=feed&start={}'.format(j))
        # url.encoding = 'utf-8' # If you need to use the Chinese characters in the page , You need to decode , Otherwise, Chinese will appear garbled 
        html = url.text
        #  Parse web pages 
        soup = BeautifulSoup(html, 'html.parser')
        #  Get all img label 
        movie = soup.find_all('div', class_='mbpho')
        # print(movie)
        #  obtain src route 
        for i in movie:
            imgsrc = i.find_all('img')[0].get('src')
            img_list.append(imgsrc)
    return img_list
i = random.randint(0, len(img_list))
print(get_img_random()[i])

Get a random picture address .
 Insert picture description here
I wrote a web version based on this , Page entrance : Keywords random pictures

2、 Birthday Book

This needs to aggregate data API Interface , This has been introduced in the second article , You can go and have a look .
The second article : Building a QQ The robot chats with her girlfriend and wakes her up

Take a look at the returned data :
 Insert picture description here
 Insert picture description here
Go straight to the code ( You need to go to the official website to apply for this interface to obtain the request key):

import requests

def birthday_book(birthday,key):
    url = "http://apis.juhe.cn/fapig/birthdayBook/query?" + 'keyword={}&key= You apply for api Request key'.format(birthday)
    #  send out get request 
    r = requests.get(url)
    #  Get the returned json data 
    result = r.json()['result'][key].replace('<p>','').replace('</p>','')
    return result

dict={
    ' character ':'nature',' love ':'love',' Fortune ':'money',' career ':'business',' health ':'health',' Lucky Numbers ':'lucky_num',' Suitable love object ':'in_love',' Suitable friends ':'friend'}
word=' Suitable love object '
print(birthday_book('08-14',str(dict[word])))

3、 Get lyrics and share music

Reference article : Netease cloud music is commonly used API( Search for , The lyrics ,mp3 download )
(1) Get the lyrics
URL:http://music.163.com/api/search/pc
submission :POST
Parameters :
s: The name of the song
offset: Offset
limit: Get the number of songs
type: type ( song :1、 Album :10、 singer :100、 song sheet :1000、 user :1002、mv:1004)

python Code :

import requests
import json

def get_lyric(song):
    url = "http://music.163.com/api/search/pc"
    pyload = {
    "s": song, "offset": 0, "limit": 1, 'type': 1}
    response = requests.post(url, data=pyload).json()
    artists = response['result']['songs'][0]['artists']
    name = ''
    for i in artists:
        name = name + '/' + i['name']
    id = response['result']['songs'][0]['id']
    url = 'http://music.163.com/api/song/media?id=' + str(id)
    r = requests.get(url)
    try:
        if len(r.json()['lyric']) <= 1:
            return ' No lyrics '
        else:
            return ' singer :' + name + '\n' + str(r.json()['lyric'])
    except:
        return ' absolute music , No lyrics '

print(get_lyric(' Your eyes are like stars '))

Return results :
 Insert picture description here
To build a robot, you need to obtain a parameter , Song key words ( You can take the author )

(2) Share music
First, you need to get the of the song id, Then through the of the robot frame cqcode To share . At present, it seems that only group chat sending is supported , Private chat didn't respond .
Document address :http://docs.go-cqhttp.org/cqcode/# Music sharing
 Insert picture description here
Get music id function :

def get_id(song):
    url = "http://music.163.com/api/search/pc"
    pyload = {
    "s": song, "offset": 0, "limit": 1, 'type': 1}
    response = requests.post(url, data=pyload).json()
    id = response['result']['songs'][0]['id']
    return id

To build a robot, you need to obtain a parameter , Song key words ( You can take the author )

Full project download address ( Configured with python Environmental Science )

The complete project includes the framework 、 The code and detailed instructions can be downloaded from the link :
QQ Robot Basic Edition ( article 1-2 All functions )
QQ Robot multifunction version ( article 1-3 All functions )

After downloading, you only need to modify several places according to the instructions to build successfully !!

 Insert picture description here

Full project download address ( Computers don't have python Environmental Science )

Computers don't have python Environment or feel that the configuration is too troublesome, you can buy it directly exe edition , As long as there is a computer, it can run !!
QQ Robot Basic Edition exe
QQ Robot multifunction version exe
Similarly, there are instructions for use , Configuration is more convenient ( Strongly recommend )!!

 Insert picture description here
But there is also a disadvantage , It's not programmable , The function has been fixed , Perfect for novices !!

Personal home page ( Including web version robot 、 Lick dog quotes online generation and keyword random pictures and other functions ): Skin children's personal site

原网站

版权声明
本文为[Skin kid LS]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230955358588.html