Last active
March 31, 2024 13:04
-
-
Save vimagick/d3389c04a768469141e8f4675317ac63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -uo pipefail | |
CURSOR=${1:-1} | |
API_URL=https://lexica.art/api/infinite-prompts | |
#HTTP_PROXY=172.16.1.48:3128 | |
OUTPUT_DIR=output | |
PAGE_NUM=0 | |
MAX_PAGE_NUM=$((10**6)) | |
mkdir -p ${OUTPUT_DIR} | |
while :; do | |
if ((++PAGE_NUM > MAX_PAGE_NUM)); then | |
echo "$(date +%FT%T) done 💯" | |
break | |
fi | |
echo -n "$(date +%FT%T) $CURSOR (#$PAGE_NUM) " | |
OUTPUT_FILE=${OUTPUT_DIR}/${CURSOR}.json | |
if [[ -s $OUTPUT_FILE.gz ]]; then | |
echo "💥" | |
break | |
fi | |
jq -n --arg text '' \ | |
--arg model 'lexica-aperture-v4' \ | |
--arg searchMode 'images' \ | |
--arg source 'search' \ | |
--argjson cursor $CURSOR \ | |
'{$text, $model, $searchMode, $source, $cursor}' | | |
curl -s -m5 ${HTTP_PROXY:+-x $HTTP_PROXY} -A 'Mozilla/5.0' -H 'Content-Type:application/json' $API_URL -d @- > ${OUTPUT_FILE} | |
NEXT_CURSOR=$(jq -e 'select(.nextCursor|type=="number").nextCursor' ${OUTPUT_FILE}) | |
if (($? == 0)); then | |
if ((NEXT_CURSOR <= CURSOR)); then | |
echo "❓" | |
break | |
fi | |
echo "✅" | |
gzip -f ${OUTPUT_FILE} | |
CURSOR=$NEXT_CURSOR | |
else | |
echo "❌" | |
((--PAGE_NUM)) | |
continue | |
fi | |
done | |
# PROMPT_URL=https://lexica.art/prompt/$PROMPT_ID | |
# IMAGE_URL=https://image.lexica.art/full_webp/$IMAGE_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment