Tokens.xml for M:tG
Go to file
ebbit1q d56eddda0c
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
2022-11-10 00:25:31 +01:00
.github/workflows fix workflow issue 2022-09-12 15:01:08 +02:00
challenge_tokens.xml Split Challenge Decks and Heros By Set (#173) 2022-08-10 14:51:15 +02:00
LICENSE Initial commit 2014-07-27 11:15:08 +08:00
README.md CI: Check image links (#131) 2022-09-12 14:13:36 +02:00
tokens.xml sort sets and cards (#165) 2022-11-10 00:25:31 +01:00
version.txt sort sets and cards (#165) 2022-11-10 00:25:31 +01:00

Discord Gitter Chat

Magic-Token Picture Health

This repo contains token information in Cockatrice's XML card database format for Magic: The Gathering.
It describes individual tokens with linked art and the relation to their creators.

For normal tokens, save the file found here: tokens.xml

For tokens from the Theros block challege decks, save the file found here: challenge_tokens.xml