v1.
This commit is contained in:
47
run/vk/send-albums.sh
Executable file
47
run/vk/send-albums.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
source $SCRIPT_DIR/constants.sh
|
||||
source $ROOT_DIR/run/evo/constants.sh
|
||||
source $SCRIPT_DIR/functions.sh
|
||||
|
||||
# Setup logging
|
||||
setup_logging
|
||||
|
||||
# Trap signals to ensure proper cleanup
|
||||
trap 'cleanup 1' HUP INT QUIT TERM
|
||||
|
||||
evoPath=$EVO_GROUPS_PATH/$EVO_API_STORE_ID
|
||||
evoFileName=`ls $evoPath -Art | tail -1`
|
||||
evoFilePath=$evoPath/$evoFileName
|
||||
vkPath=$VK_ALBUMS_PATH/$VK_API_GROUP_ID
|
||||
vkFileName=`ls $vkPath -Art | tail -1`
|
||||
vkFilePath=$vkPath/$vkFileName
|
||||
|
||||
# Load whitelist
|
||||
readarray -t whitelist < "$ROOT_DIR/vk/whitelist"
|
||||
|
||||
# Filter items by whitelist
|
||||
readarray items < <(yq -o=j -I=0 ".items[]" $evoFilePath)
|
||||
|
||||
for item in "${items[@]}"; do
|
||||
evoTitle=`echo $item | yq .name`
|
||||
# Check if group is whitelisted
|
||||
if [[ ! " ${whitelist[@]} " =~ " ${evoTitle} " ]]; then
|
||||
continue
|
||||
fi
|
||||
found=`evoTitle="$evoTitle" yq '.response.items[] | select(.title==strenv(evoTitle))' $vkFilePath`
|
||||
if [[ ! -n "$found" ]]; then
|
||||
echo "$(timestamp) [REQUEST] Creating album: $evoTitle" >> "$LOG_FILE"
|
||||
response=$(curl -s -w "%{http_code}" -H "Authorization: Bearer $VK_API_USER_TOKEN" \
|
||||
-F owner_id=$VK_API_PARAM_OWNER_ID \
|
||||
-F title="$evoTitle" \
|
||||
$VK_API_ADD_ALBUM)
|
||||
http_code=${response: -3}
|
||||
response_body=${response:0:-3}
|
||||
echo "$(timestamp) [RESPONSE] code=$http_code body=$response_body" >> "$LOG_FILE"
|
||||
fi
|
||||
done
|
||||
|
||||
# Use the cleanup function instead of directly exiting
|
||||
cleanup 0
|
||||
Reference in New Issue
Block a user