From e5fd30b24dc83ecb3d079062fa503a64a7b42910 Mon Sep 17 00:00:00 2001 From: panqihua Date: Mon, 30 May 2022 15:38:15 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=88=A0=E9=99=A4config=E3=80=82json=20rule?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9=202.=E4=BF=AE=E5=A4=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B8=85=E7=90=86=E6=96=87=E4=BB=B6=E9=80=BB=E8=BE=91?= =?UTF-8?q?=203.=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=204.?= =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E5=8E=8B=E7=BC=A9=E6=A0=BC=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BAwebp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pixiv/config.json.example | 1 - pixiv/pixiv.sh | 37 +++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/pixiv/config.json.example b/pixiv/config.json.example index 13a8722..18a7261 100644 --- a/pixiv/config.json.example +++ b/pixiv/config.json.example @@ -4,7 +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/,分别是插画/动图/漫画", - "rule":{"匹配需要转义的内容":"转换后的值","&":"&","<":"<"}, "sleep":{ "text":10, "image":60 diff --git a/pixiv/pixiv.sh b/pixiv/pixiv.sh index 450293e..f6d42a0 100644 --- a/pixiv/pixiv.sh +++ b/pixiv/pixiv.sh @@ -163,7 +163,7 @@ today=`date "+%Y-%m-%d"` _today=`date "+%Y%m%d"` rank_json=$today.json -rule=`cat $config_file | jq .rule|jq to_entries|jq 'map("sed -e \"s/\\\\"+.key+"/\\\\"+.value+"/g\"")'|jq -r '.[]'|sed ':a;N;s/\n/|/;t a;'` +rule='sed -e "s/\\&/\\&/g"|sed -e "s/\\</\\/g"' sleepText=`cat $config_file | jq .sleep.text` sleepImage=`cat $config_file | jq .sleep.image` @@ -175,7 +175,7 @@ then curl -v $rank_url >$rank_json fi length=`jq '.contents|length' $rank_json` -fileCountSize=0 + fileList='' media='' fileCount=0 @@ -279,8 +279,8 @@ do original_file_size=`du -b $original_file_name|awk '{print $1}'` if [ $original_file_size -gt $maxFileSize ] then - echo "${original_file_name}文件体积超过${maxFileSize}字节,需要在线压缩" - result=`curl -v -X POST -d "{\"apikey\": \"$convertio_apikey\", \"input\":\"upload\", \"outputformat\":\"jpeg\"}" http://api.convertio.co/convert` + echo "${original_file_name}文件体积:${original_file_size}字节超过${maxFileSize}字节限制,需要在线压缩" + result=`curl -v -X POST -d "{\"apikey\": \"$convertio_apikey\", \"input\":\"upload\", \"outputformat\":\"webp\"}" http://api.convertio.co/convert` if [ `echo $result|jq -r .status` = ok ] then @@ -292,10 +292,11 @@ do do sleep 10 result=`curl -v -X GET http://api.convertio.co/convert/$id/status` + echo "转换响应:$result" if [[ `echo $result|jq -r .status` = ok && `echo $result|jq -r .data.step` = finish ]] then - echo $result|jq .data.output.url|xargs curl -v -o $original_file_name - PutObject $original_file_name + echo $result|jq .data.output.url|xargs curl -v -o $webp_file_name + PutObject $webp_file_name break elif [ `echo $result|jq -r .status` = error ] then @@ -342,20 +343,23 @@ do fileList="$fileList -F $webp_file_name=@$webp_file_name" fileCount=$((fileCount + 1)) fileSize=`du $webp_file_name | awk '{print $1}'` - fileCountSize=$((fileCountSize + fileSize)) - echo "fileCountSize=$fileCountSize,fileCount=$fileCount" + echo "fileCount=$fileCount" 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"` - message_id=`echo $result|jq .result.message_id` - echo "message_id:$message_id" - sleep $sleepImage - curl -v -d chat_id=$chat_id -d reply_to_message_id=$message_id -d text="以上作品日榜排名分别是 #排名${start_rank}_${end_rank} #rank${start_rank}_${end_rank} ,点击作品可以查看pid/标题/画师/tag信息." $baseApi/sendMessage + + if [ `echo $result|jq .ok` == "true" ] + 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 - fileCountSize=0 fileList='' media='' fileCount=0 @@ -367,7 +371,8 @@ 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 -find -type f -mtime +7|grep html -find -type f -mtime +7|grep json -find -type f -mtime +7|grep webp +find -type f -mtime +7|grep html|xargs rm -f +find -type f -mtime +7|grep json|xargs rm -f +find -type f -mtime +7|grep webp|xargs rm -f +find -type f -mtime +7|grep info|xargs rm -f DeleteMultipleObjects \ No newline at end of file