fix: So, I fucked up the last time when I thought I totally fixed this.

the TEMP_FILE, keeping track of intermedia changes wasn't necessarily keeping track of all the data I wanted it to, it could behave randomly and it will give you redundant data, and you lose novel data. so no I introduced a new TEMP_FILE_1 (TEMP_FILE new name) and a TEMP_FILE_2 .

TEMP_FILE_1 will as usual, like before, contain all the yet-to-be-converted-into-a-single-array data and TEMP_FILE_2 will be a used to keep track of LAST_POST_ID in the current request scope.
master
FrailLeaf 1 year ago
parent f67a79245e
commit 1eb6ae5ce5

@ -62,8 +62,9 @@ fi
echo "Your Instance URL -> $URL"
echo "Your Account name -> $NAME"
# Temp file
TEMP_FILE="post_data.json"
# Temp files
TEMP_FILE_1="post_data.json"
TEMP_FILE_2="post_data_added.json"
# Output File
ARCHIVED_POSTS_FILE="archived_posts-${NAME}.json"
@ -114,22 +115,24 @@ downloadPosts () {
-H "Authorization: Bearer ${TOKEN}" \
-X GET "${URL}/api/v1/accounts/${NAME}/statuses?exclude_reblogs=true&limit=${TO_DOWNLOAD}" \
| jq '[.[] | {post: .pleroma.content."text/plain", id: .id, created_at: .created_at}]' \
>> "$TEMP_FILE"
>> "$TEMP_FILE_1"
else
curl \
-H "Authorization: Bearer ${TOKEN}" \
-X GET "${URL}/api/v1/accounts/${NAME}/statuses?exclude_reblogs=true&limit=${TO_DOWNLOAD}&max_id=${LAST_POST_ID}" \
| jq '[.[] | {post: .pleroma.content."text/plain", id: .id, created_at: .created_at}]' \
>> "$TEMP_FILE"
>> "$TEMP_FILE_1"
fi
# Collect the post id of the last post in the current iteration of $MAX_POSTS_PER_REQUEST posts requested
# the (( $TO_DOWNLOAD - 1 )) is because of the array indexing rule, and that is they way I can grab the final post ID in this list
LAST_POST_ID="$(jq -s 'add | .['"(( $TO_DOWNLOAD - 1 ))"'] | .id' $TEMP_FILE)"
jq -s 'add' "$TEMP_FILE_1" > "$TEMP_FILE_2"
TOTAL_POST_IDS="$(jq '.[].id' $TEMP_FILE_2 | wc -l)"
LAST_POST_ID="$(jq '.['"(( $TOTAL_POST_IDS - 1 ))"'] | .id' $TEMP_FILE_2)"
LAST_POST_ID="${LAST_POST_ID/#\"/}"
LAST_POST_ID="${LAST_POST_ID/%\"/}"
echo "$POST_ID"
rm "$TEMP_FILE_2"
}
@ -156,8 +159,8 @@ do
done
# merge the array data into a single array
jq -s 'add' "$TEMP_FILE" > "$ARCHIVED_POSTS_FILE"
jq -s 'add' "$TEMP_FILE_1" > "$ARCHIVED_POSTS_FILE"
rm $TEMP_FILE
rm $TEMP_FILE_1
echo "Posts archived! You can find them here: $ARCHIVED_POSTS_FILE"

Loading…
Cancel
Save