自建青龙服务器,一键拉取所有脚本,解放双手

首先你需要知道你的IP+port

齐次知道使用浏览器的开发者工具(用来获取 Authorization

不知道,请先自行了解

直接给代码 (下面是Python的,还有其他版本的,请自行验证)其他语言版本

import requests
import time
import os
import logging

API_BASE_URL = "http://YOURIP:5700"
API_TOKEN = "YOUR_Authorization"

# 设置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

def main():
    try:
        record_data = get_data("/api/scripts?t=")
        logger.info("获取到的body code: %s", record_data.get("code"))

        for val in record_data.get("data", []):
            try:
                if val.get("children"):
                    for child_val in val["children"]:
                        child_data = get_data("/api/scripts/%s?path=%s&t=" % (child_val["title"], child_val["parent"]))
                        download_file(child_data.get("data", ""), child_val["parent"], child_val["title"])
                else:
                    child_data = get_data("/api/scripts/%s?path=&t=" % val["title"])
                    download_file(child_data.get("data", ""), "", val["title"])
            except Exception as e:
                logger.error("处理子项目时出错: %s", str(e))
        logger.info("执行完毕")
    except Exception as e:
        logger.error("An error occurred: %s", str(e))

def get_data(url_str):
    try:
        timestamp = str(int(time.time() * 1000))
        full_url = API_BASE_URL + url_str + timestamp
        logger.info(full_url)
        headers = {"Authorization": "Bearer " + API_TOKEN}
        resp = requests.get(full_url, headers=headers)
        resp.raise_for_status()  # Raise an error for non-2xx responses
        return resp.json()
    except requests.exceptions.RequestException as e:
        raise Exception("Request error: " + str(e))

def download_file(body, path, name):
    try:
        file_path = os.path.join(".", name)
        if path:
            if not os.path.exists(path):
                os.makedirs(path)
                os.chmod(path, 0o777)
            file_path = os.path.join(path, name)
        with open(file_path, "wb") as f:
            if isinstance(body, str):
                # If body is a string, encode it to bytes before writing
                body = body.encode("utf-8")
            f.write(body)
    except Exception as e:
        raise Exception("File download error: " + str(e))

if __name__ == "__main__":
    main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝兔兔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值