From 7db8545de51cc9db2ba98af952b9ddb87c016776 Mon Sep 17 00:00:00 2001 From: DDSRem <73049927+DDSRem@users.noreply.github.com> Date: Sun, 1 Dec 2024 11:56:05 +0800 Subject: [PATCH] feat: auto get folder id --- glue_python/get_folder_id/get_folder_id.py | 19 ++++++++++ glue_python/get_folder_id/get_folder_id.sh | 40 ++++++++++++++++++++++ glue_python/get_folder_id/requirements.txt | 1 + 3 files changed, 60 insertions(+) create mode 100644 glue_python/get_folder_id/get_folder_id.py create mode 100644 glue_python/get_folder_id/get_folder_id.sh create mode 100644 glue_python/get_folder_id/requirements.txt diff --git a/glue_python/get_folder_id/get_folder_id.py b/glue_python/get_folder_id/get_folder_id.py new file mode 100644 index 000000000..efefd6443 --- /dev/null +++ b/glue_python/get_folder_id/get_folder_id.py @@ -0,0 +1,19 @@ +from aligo import Aligo + +ali = Aligo(refresh_token='316bb9995a2b4ac79632040687a08be2') + +# 这里默认使用资源盘 +v2_user = ali.v2_user_get() +resource_drive_id = v2_user.resource_drive_id +ali.default_drive_id = resource_drive_id + +file_list = ali.get_file_list() +folder_id = '' +for folder in file_list: + if folder.name == '小雅转存文件夹': + folder_id = folder.file_id + break +if not folder_id: + folder_id = ali.create_folder(name='小雅转存文件夹').file_id + +print(folder_id) diff --git a/glue_python/get_folder_id/get_folder_id.sh b/glue_python/get_folder_id/get_folder_id.sh new file mode 100644 index 000000000..aaeb7b97b --- /dev/null +++ b/glue_python/get_folder_id/get_folder_id.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +Green="\033[32m" +Red="\033[31m" +Yellow='\033[33m' +Font="\033[0m" +INFO="[${Green}INFO${Font}]" +ERROR="[${Red}ERROR${Font}]" +WARN="[${Yellow}WARN${Font}]" +function INFO() { + echo -e "${INFO} ${1}" +} +function ERROR() { + echo -e "${ERROR} ${1}" +} +function WARN() { + echo -e "${WARN} ${1}" +} + +if ! folderid=$(python /get_folder_id/get_folder_id.py); then + ERROR "自动获取 阿里云盘转存目录 folder id 失败,请手动获取!" + exit 1 +fi +if [ -n "${folderid}" ]; then + INFO "阿里云盘转存目录 folder id:${folderid}" +else + ERROR "自动获取 阿里云盘转存目录 folder id 失败,请手动获取!" + exit 1 +fi + + +echo "${folderid}" > /data/temp_transfer_folder_id.txt +echo "r" > /data/folder_type.txt + +refresh_token=$(sed 's/:\s*/:/g' /root/.aligo/aligo.json | sed -n 's/.*"refresh_token":"\([^"]*\).*/\1/p') + +INFO "自动刷新 refresh_token:${refresh_token}" + +echo "${refresh_token}" > /data/mytoken.txt + diff --git a/glue_python/get_folder_id/requirements.txt b/glue_python/get_folder_id/requirements.txt new file mode 100644 index 000000000..900cc0879 --- /dev/null +++ b/glue_python/get_folder_id/requirements.txt @@ -0,0 +1 @@ +aligo \ No newline at end of file