Created
August 6, 2022 09:25
-
-
Save ZaptorZap/e8881170180f7d61b9efe71aee288861 to your computer and use it in GitHub Desktop.
Generate TR cutoffs or "thresholds" for the TETR.IO webgame's ranked "TETRA LEAGUE" by interfacing with its public TETRA CHANNEL API. • Output is in valid JSON format.
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 | |
wget https://ch.tetr.io/api/users/lists/league/all --output-document ~/Downloads/all.json | |
originalranks=( "x" "u" "ss" "s+" "s" "s-" "a+" "a" "a-" "b+" "b" "b-" "c+" "c" "c-" "d+" ) | |
originaltuiiranks=( "x" "u" "ss" "sp" "s" "sm" "ap" "a" "am" "bp" "b" "bm" "cp" "c" "cm" "dp" ) | |
# short for Original Tenchi Ultra Improved Indistinguishable Ranks • created this way for compatibility with applications that depended on the output of data found on https://tetrio.team2xh.net/?t=ranks | |
printf "{\"date\":\"$(date --utc +"%Y-%m-%d %H:%M:%S UTC")\",\"thresholds\":[" > ~/Downloads/thresholds.json # begin the JSON object | |
for index in {0..15}; do | |
printf "{\"rank\":\"${originaltuiiranks[$index]}\",\"threshold\":" >> ~/Downloads/thresholds.json # STEP ONE: starting the threshold with tenchi's special name | |
rankplayercount="$(jq --raw-output "[.data.users[] | select(.league.rank == \"${originalranks[$index]}\")] | length" ~/Downloads/all.json)" # how many people are in this rank? | |
rankmiddlemostplayerid="$(jq --raw-output "[.data.users[] | select(.league.rank == \"${originalranks[$index]}\")] | .[$(( $rankplayercount / 2 ))]._id" ~/Downloads/all.json)" # who's straight in the middle, guaranteed to be in the rank we're querying? | |
sleep 1s # to comply with osk's 1-second API wait time—although processing all of this jq is likely going to take longer than a second | |
lowerplacement="$(curl -s https://ch.tetr.io/api/users/$rankmiddlemostplayerid | jq --join-output ".data.user.league.prev_at")" # what's their users stats say about the cutoff of this rank? we'll only be referencing this once, so no need for more temporary files | |
jq --join-output ".data.users[$lowerplacement].league.rating | floor" ~/Downloads/all.json >> ~/Downloads/thresholds.json # STEP TWO: combine our work from before and get the cutoff | |
printf "}," >> ~/Downloads/thresholds.json # STEP THREE: closing this part and starting the next one | |
done | |
printf "{\"rank\":\"d\",\"threshold\":" >> ~/Downloads/thresholds.json | |
jq --join-output '[.data.users[] | select(.league.rank == "d")] | .[-1].league.rating | floor' ~/Downloads/all.json >> ~/Downloads/thresholds.json | |
printf "}]}" >> ~/Downloads/thresholds.json | |
rm ~/Downloads/all.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment