mirror of
https://github.com/Cockatrice/Magic-Token.git
synced 2026-08-23 09:54:39 -05:00
sort sets and cards (#165)
* use proper set code for fnm 2012 token
* change order of each set using script
some sets were not properly sorted
the release date of SLD might be contestable but the script seems to
have found 27 real discrepancies
the release date is as shown in scryfall, eg SLD has a date of 2019-12-02
bash is a real programming language and I can put it on my resume,
don't tell me otherwise:
set -eo pipefail
mapfile -t sets < <(LC_ALL=C curl -L 'https://mtgjson.com/api/v5/SetList.json' | jq -r '.data[]|.releaseDate,.code' | sed 'N;s/\n/ /' | sort -r | sed 's/.* //')
setrx="<set[^>]*>([^<]+)</set>"
list=()
while IFS= read -r line; do
if [[ $line =~ $setrx ]]; then
code="${BASH_REMATCH[1]}"
list+=("$code" "$line")
elif [[ $code ]]; then
for set_ in "${sets[@]}"; do
for (( i=0; i<${#list[@]}; i+=2 )); do
code="${list[$i]}"
if [[ $set_ == "$code" ]]; then
echo "${list[$i+1]}"
fi
done
done
code=""
list=()
echo "$line"
else
echo "$line"
fi
done <tokens.xml | sponge tokens.xml
* sort all cards using script
actually there was only one discrepancy in the file before " Token" was
added to a lot of entries (Wasp)
however the addition has changed the sort order for many cards,
eg "Bird Token" vs "Bird Soldier Token"
cards after the last normal token have not been included (Zombie Wizard)
still using bash of course:
last="Zombie Wizard Token"
startrx=" -->"
namerx="<name>([^<]*)</name>"
endrx="</card>"
declare -A list # associative array
{
while IFS= read -r line; do
echo "$line"
if [[ $line =~ $startrx ]]; then # eat first comment
break
fi
done
while
while
IFS= read -r line || exit 2
card+="$line
"
[[ ! $line =~ $namerx ]]
do :; done
name="${BASH_REMATCH[1]}"
while
IFS= read -r line || exit 3
card+="$line
"
[[ ! $line =~ $endrx ]]
do :; done
list[ "$name"]="$card"
keys+="
$name"
card=""
[[ $name != "$last" ]]
do :; done
<<<"${keys:1}" LC_ALL=C sort --ignore-case | while IFS= read -r key; do
echo -n "${list[ $key]}"
done
cat
} <tokens.xml | sponge tokens.xml
* sort reverse-related tags again
slightly changed script from 6ca51e5
tag="reverse-related"
relationrx="<$tag([^>]*)>([^<]*)</$tag>"
declare -A list # associative array
while IFS= read -r line; do
if [[ $line =~ $relationrx ]]; then
yes=1
name="${BASH_REMATCH[2]}"
args="${BASH_REMATCH[1]}"
key="$name $(printf "%03d" "${#args}")$args"
list["$key"]="$line"
keys+="
$key"
elif [[ $yes ]]; then
# LC_ALL=C determines the sort behavior!
<<<"${keys:1}" LC_ALL=C sort --ignore-case | while read -r; do
echo "${list[$REPLY]}"
done
yes=""
list=()
keys=""
echo "$line"
else
echo "$line"
fi
done <tokens.xml | sponge tokens.xml
* update version
This commit is contained in:
1756
tokens.xml
1756
tokens.xml
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
20221109c
|
||||
20221109d
|
||||
|
||||
Reference in New Issue
Block a user