Skip to content

Instantly share code, notes, and snippets.

@Karitham
Last active March 8, 2022 08:11
Show Gist options
  • Save Karitham/735d2ef9fbbbaf7a1fdd4bcb9c2e88ad to your computer and use it in GitHub Desktop.
Save Karitham/735d2ef9fbbbaf7a1fdd4bcb9c2e88ad to your computer and use it in GitHub Desktop.
Updating a character image in the WaifuBot DB with `usql`, `jq` and `curl`
#! /bin/bash
query=$(curl 'https://graphql.anilist.co/' \
-s \
-H 'content-type: application/json' \
-d "{\"query\":\"query(\$id: Int) {Character(id:\$id){image{large}}}\",\"variables\":{\"id\":$1}}")
URL=$(echo $query | jq -r '.data.Character.image.large')
if [ $URL != "null" ]; then
echo updating $1 to $URL
usql $DB_URL -c "UPDATE characters SET image = '$URL' WHERE id = $1" -q
else
echo no image for $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment