Created
February 22, 2021 15:51
-
-
Save theKAKAN/dc18614e4a6fd9bfd15a8856640e237f to your computer and use it in GitHub Desktop.
Fetch your "Completed" section of anime or manga and their IDs as well as their ratings using bash and put them into a CSV
This file contains hidden or 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 | |
# Config | |
USERNAME="KAKAN" | |
mediaType="ANIME" | |
# Let's get it using HTTP | |
AFTER=$( http --pretty none -b -f https://kitsu.io/api/graphql query="query{findProfileBySlug(slug: \"$USERNAME\"){library{completed(first:100, mediaType:$mediaType){pageInfo{startCursor}}}}}" \ | |
| jq .data.findProfileBySlug.library.completed.pageInfo.startCursor ) | |
hasNextPage=true | |
# Let's reset the CSV file | |
echo "Anime ID, Rating" > info.csv | |
while $hasNextPage ; do | |
# Remove the first and last quotes; "Mx" becomes Mx | |
AFTER="${AFTER%\"}" | |
AFTER="${AFTER#\"}" | |
query="query { | |
findProfileBySlug(slug:\"$USERNAME\"){ | |
library { | |
completed( first: 100, mediaType:$mediaType, after:\"$AFTER\" ){ | |
pageInfo { | |
hasNextPage | |
endCursor | |
} | |
nodes { | |
media { | |
id | |
} | |
rating | |
} | |
} | |
} | |
} | |
}" | |
# The script should be one liner with updated variables | |
script="$(echo $query)" | |
output=$( http --pretty none --style=bw -b -f https://kitsu.io/api/graphql query="$script" ) | |
hasNextPage=$( echo "$output" | jq .data.findProfileBySlug.library.completed.pageInfo.hasNextPage ) | |
AFTER=$( echo "$output" | jq .data.findProfileBySlug.library.completed.pageInfo.endCursor ) | |
# Anime ID | |
id=$(echo "$output" | jq .data.findProfileBySlug.library.completed.nodes[].media.id) | |
# Remove the quotes from here as well | |
# Also makes it a one-liner separated by spaces | |
# Also, turn it into an array | |
id=( $( echo $id | sed 's/"//g' ) ) | |
# Rating | |
rating=$( echo "$output" | jq .data.findProfileBySlug.library.completed.nodes[].rating) | |
# Make it a one liner and turn it into an array | |
rating=( $( echo $rating ) ) | |
# Let's get array length | |
length=${#id[@]} | |
for(( i=0; i < ${length}; i++ )); | |
do | |
echo "${id[i]},${rating[i]}" >> info.csv | |
done | |
echo "Inserted round $AFTER" | |
# PHEW | |
done | |
echo "Inserted everything successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I hate myself for this horrible code, but this took me some time to write as well xD
So, to use it: download the file, set your username and the mediaType( can be either ANIME or MANGA, in caps ) and run the file.
It should put everything in a info.csv file
Do note that subsequent runs overwrites that file, so keep it safe.