Skip to content

Commit

Permalink
feat: auto get folder id
Browse files Browse the repository at this point in the history
  • Loading branch information
DDSRem committed Dec 1, 2024
1 parent 3bf8089 commit 7db8545
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
19 changes: 19 additions & 0 deletions glue_python/get_folder_id/get_folder_id.py
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions glue_python/get_folder_id/get_folder_id.sh
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions glue_python/get_folder_id/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aligo

0 comments on commit 7db8545

Please sign in to comment.