From 814f3b85292c5e333ac3d22347eac144b658512e Mon Sep 17 00:00:00 2001 From: panqihua Date: Tue, 31 May 2022 13:15:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85tg=E8=AF=B7=E6=B1=82=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=A3=80=E6=B5=8B=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pixiv/config.json.example | 4 ---- pixiv/pixiv.sh | 44 +++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/pixiv/config.json.example b/pixiv/config.json.example index 18a7261..f2bb772 100644 --- a/pixiv/config.json.example +++ b/pixiv/config.json.example @@ -4,10 +4,6 @@ "chatId": "推送目标聊天的唯一标识符或目标频道的用户名", "mode": "Pixiv排行榜类型,有效值:daily/weekly/monthly/rookie/daily_r18/weekly_r18/male_r18/female_r18/r18g,分别是日榜/周榜/月榜/新人榜/日榜r18/周榜r18/受男性欢迎r18/受女性欢迎r18/r18g", "content": "Pixiv排行榜类型,有效值:illust/ugoira/manga/,分别是插画/动图/漫画", - "sleep":{ - "text":10, - "image":60 - }, "aliyun_oss":{ "Host":"Endpoint(地域节点)", "accelerateHost":"传输加速Endpoint(地域节点)", diff --git a/pixiv/pixiv.sh b/pixiv/pixiv.sh index f6d42a0..8515a01 100644 --- a/pixiv/pixiv.sh +++ b/pixiv/pixiv.sh @@ -146,6 +146,28 @@ function fileSizeStr(){ fi } +function Request(){ + while true + do + echo "发送消息命令:$1" + result=`bash -c "$1"` + echo "请求响应:$result" + if [ `echo $result|jq .ok` = true ] + then + return 1 + elif [ `echo $result|jq .error_code` -eq 429 ] + then + second=`echo $result|jq .parameters.retry_after` + sleep $second + echo "${second}后再发起请求" + Request $1 + else + echo "执行命令遇到未知错误!" + return 0 + fi + done +} + basePath=`cat $config_file|jq -r .basePath` if [ ! -f $basePath ] then @@ -165,10 +187,8 @@ rank_json=$today.json rule='sed -e "s/\\&/\\&/g"|sed -e "s/\\</\\/g"' -sleepText=`cat $config_file | jq .sleep.text` -sleepImage=`cat $config_file | jq .sleep.image` -curl -v -d chat_id=$chat_id -d parse_mode=HTML -d text="Pixiv排行榜已更新,$sleepText秒后开始处理$today日榜数据。#date$_today #日期$_today %0A%0A排名是什么?%0A排名是以pixiv上所有公开作品为对象的统计以及排名。%0A毎日0:00~23时59分59秒的阅览树・「赞!」数等为排名的依据,期结果由pixiv独自的算法「pixiv rank β」决定。统计结果于每日中午12:00公开。%0A有关排行榜" $baseApi/sendMessage -sleep $sleepText +Request "curl -v -d chat_id=$chat_id -d parse_mode=HTML -d text=\"Pixiv排行榜已更新,开始处理$today日榜数据。#date$_today #日期$_today %0A%0A排名是什么?%0A排名是以pixiv上所有公开作品为对象的统计以及排名。%0A毎日0:00~23时59分59秒的阅览树・「赞!」数等为排名的依据,期结果由pixiv独自的算法「pixiv rank β」决定。统计结果于每日中午12:00公开。%0A有关排行榜\" $baseApi/sendMessage" + if [ ! -f $rank_json ] then echo "get data from $rank_url" @@ -347,19 +367,17 @@ do fi if [[ $fileCount -eq $maxFileCount ]] then - command="curl -v -F chat_id=$chat_id $fileList -F media='[`echo $media | cut -c 2-`]' $baseApi/sendMediaGroup" - echo "上传图片命令:$command" - result=`bash -c "$command"` - - if [ `echo $result|jq .ok` == "true" ] + Request "curl -v -F chat_id=$chat_id $fileList -F media='[`echo $media | cut -c 2-`]' $baseApi/sendMediaGroup" + if [ `echo $?` -eq 1 ] then sleep $sleepImage text="以上作品日榜排名分别是 #排名${start_rank}_${end_rank} #rank${start_rank}_${end_rank} ,点击作品可以查看pid/标题/画师/tag信息." else text="#排名${start_rank}_${end_rank} #rank${start_rank}_${end_rank}作品上传失败,请联系管理员" - fi - curl -v -d chat_id=$chat_id -d text=$text $baseApi/sendMessage - sleep $sleepText + fi + + Request "curl -v -d chat_id=$chat_id -d text=\"$text\" $baseApi/sendMessage" + fileList='' media='' fileCount=0 @@ -369,7 +387,7 @@ done next_expected_at=`curl -v https://cronitor.io/api/monitors/$CronitorJobName -u $CronitorKey:''|jq .next_expected_at` -curl -v -d chat_id=$chat_id -d text="以上就是$today日榜前${length}名作品,本次推送完毕,下次推送时间预计是`date -d @$next_expected_at '+%Y-%m-%d %H:%M:%S'`,如有问题请联系管理员。 #date$_today #日期$_today " $baseApi/sendMessage +Request "curl -v -d chat_id=$chat_id -d text=\"以上就是$today日榜前${length}名作品,本次推送完毕,下次推送时间预计是`date -d @$next_expected_at '+%Y-%m-%d %H:%M:%S'`,如有问题请联系管理员。 #date$_today #日期$_today \" $baseApi/sendMessage" find -type f -mtime +7|grep html|xargs rm -f find -type f -mtime +7|grep json|xargs rm -f