scrcards/fetch_api.sh

71 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Ensure both cursor and limit arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <cursor> <limit>"
exit 1
fi
cursor=$1
limit=$2
# Construct the JSON payload with the provided cursor and limit
json_payload=$(cat <<EOF
{
"0": {
"json": {
"query": "",
"sort": "relevance",
"set": "bet",
"filters": [],
"limit": $limit,
"variantLimit": false,
"collectionLimit": false,
"cursor": $cursor,
"direction": "forward"
}
}
}
EOF
)
# Print the JSON payload for debugging
echo "JSON Payload:"
echo "$json_payload"
# URL encode the JSON payload
url_encoded_json=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$json_payload'''))")
# Print the URL-encoded JSON payload for debugging
echo "URL-encoded JSON Payload:"
echo "$url_encoded_json"
# Construct the full URL
api_url="https://curiosa.io/api/trpc/card.search?batch=1&input=$url_encoded_json"
# Print the full API URL for debugging
echo "Full API URL:"
echo "$api_url"
# Run the curl command and output the response as JSON
curl "$api_url" \
--compressed \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0' \
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Referer: https://curiosa.io/cards?set=bet' \
-H 'content-type: application/json' \
-H 'x-build-id: a68dd8c6f6e3b605951c534ad22e788557cabd0d' \
-H 'x-trpc-source: nextjs-react' \
-H 'DNT: 1' \
-H 'Sec-GPC: 1' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Priority: u=4' \
-H 'TE: trailers'