周末无聊的时候在家里折腾了一个qq机器人推送api,结果在github上找到了一些资料,终于实现了新帖qq机器人推送到qq群
插件必须在python3环境下操作,如果你没有就安装,如果不会那就无缘。
这个脚本是利用了一位大佬制作的api,文章结尾有提及相关github

go-cqhttp和脚本都支持在linux运行,所以你也可以在linux平台上挂机器人和执行脚本,我是在腾讯云的3年130的真香鸡上用windows搭建的

利用go-cqhttp搭建qq机器人推送hostloc新帖

利用go-cqhttp搭建qq机器人推送hostloc新帖

安装go-cqhttp

go-cqhttp安装教程

创建python脚本 -推送到qq群

import requests
import time
from urllib import parse

hostloc_list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ]
hostloc_title = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ]
url_1 = "https://www.hostloc.com/"
#这里输入qq群号码,和go-cqhttp端口
qq='817933066'
port='5700'
while True:
    try:
        with requests.get('https://hostloc.cherbim.ml/', stream=True, timeout=5) as r:
            print(time.strftime("%m-%d %H:%M:%S", time.localtime()))
            for i in r.json()["new_data"][0][15:]:
                if i['主题ID'] in hostloc_list or i['主题'] in hostloc_title:
                    pass
                else:
                    hostloc_list = hostloc_list[1::]
                    hostloc_list.append(i['主题ID'])
                    hostloc_title = hostloc_title[1::]
                    hostloc_title.append(i['主题'])
                    a = "https://www.hostloc.com/thread-{0}-1-1.html".format(i['主题ID'])
                    time_1 = time.strftime("%Y-%m-%d  %H:%M:%S", time.localtime())
                    if "论坛bug,此贴内容无法查看~" not in i['主题内容'][0:100]:
                        a = a
                    else:
                        a = f"<s>{a}</s>"
                    text = '主        题:' + "{}".format(i['主题'].replace("&", "%26").replace("<", "%26lt%3b").replace(">", "%26gt%3b").replace("#", " ")) + '\n' + '发  布  者:' + '''{1}'''.format(i['发布者链接'], i['发布者']) + '\n' + '时        间:' + time_1 + '\n' + '内容预览:' + '''{0}'''.format(i['主题内容'][0:100].replace("&", "%26").replace("<", "%26lt%3b").replace(">", "%26gt%3b").replace("#", " ")) + "\n" + "直达链接: " + a
                    print(text)
                    requests.get('http://127.0.0.1:' + port + '/send_group_msg?group_id=' + qq + '&message=' + text)
            time.sleep(2)
    except Exception:
        print("网络错误,请稍后重试")
        time.sleep(5)

创建python脚本 -推送到个人qq

import requests
import time
from urllib import parse

hostloc_list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ]
hostloc_title = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ]
url_1 = "https://www.hostloc.com/"
#这里输入qq号码,和go-cqhttp端口
qq='504888738'
port='5700'
while True:
    try:
        with requests.get('https://hostloc.cherbim.ml/', stream=True, timeout=5) as r:
            print(time.strftime("%m-%d %H:%M:%S", time.localtime()))
            for i in r.json()["new_data"][0][15:]:
                if i['主题ID'] in hostloc_list or i['主题'] in hostloc_title:
                    pass
                else:
                    hostloc_list = hostloc_list[1::]
                    hostloc_list.append(i['主题ID'])
                    hostloc_title = hostloc_title[1::]
                    hostloc_title.append(i['主题'])
                    a = "https://www.hostloc.com/thread-{0}-1-1.html".format(i['主题ID'])
                    time_1 = time.strftime("%Y-%m-%d  %H:%M:%S", time.localtime())
                    if "论坛bug,此贴内容无法查看~" not in i['主题内容'][0:100]:
                        a = a
                    else:
                        a = f"<s>{a}</s>"
                    text = '主        题:' + "{}".format(i['主题'].replace("&", "%26").replace("<", "%26lt%3b").replace(">", "%26gt%3b").replace("#", " ")) + '\n' + '发  布  者:' + '''{1}'''.format(i['发布者链接'], i['发布者']) + '\n' + '时        间:' + time_1 + '\n' + '内容预览:' + '''{0}'''.format(i['主题内容'][0:100].replace("&", "%26").replace("<", "%26lt%3b").replace(">", "%26gt%3b").replace("#", " ")) + "\n" + "直达链接: " + a
                    print(text)
                    requests.get('http://127.0.0.1:' + port + '/send_private_msg?user_id=' + qq + '&message=' + text)
            time.sleep(2)
    except Exception:
        print("网络错误,请稍后重试")
        time.sleep(5)

运行脚本开始推送

cd到你的脚本位置,运行 python 脚本名.py 就可以开始推送了,脚本下载

下载信息

部分资源来源于网络如有侵权,请联系删除

github相关资料
https://github.com/MoeList/Hostloc-Q-Bot
https://github.com/w2r/hostloc2tg