mirror of
https://github.com/Respect/Validation.git
synced 2024-05-06 00:13:16 +02:00
bb9ff1dba0
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
40 lines
1.3 KiB
Bash
Executable file
40 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Usage: {script}
|
|
# Update the list of currency codes
|
|
|
|
set -euo pipefail
|
|
|
|
declare -r IFS=$'\n'
|
|
|
|
declare -r LIST_URL="https://www.currency-iso.org/dam/downloads/lists/list_one.xml"
|
|
declare -r LIST_FILENAME=$(mktemp)
|
|
|
|
declare -r RULE_FILENAME=$(dirname "${BASH_SOURCE}")/../library/Rules/CurrencyCode.php
|
|
declare -r RULE_FILENAME_TEMPORARY=$(mktemp)
|
|
|
|
echo "- Downloading list"
|
|
curl --silent --location "${LIST_URL}" --output "${LIST_FILENAME}"
|
|
|
|
declare -r CURRENCY_CODES_COUNT=$(grep "<CcyNtry>" "${LIST_FILENAME}" | wc --lines)
|
|
|
|
echo "- Creating temporary file"
|
|
{
|
|
sed -n "/^</,/ return \[/p" "${RULE_FILENAME}"
|
|
for index in $(seq 1 ${CURRENCY_CODES_COUNT}); do
|
|
declare name=$(xmlstarlet sel --template --value-of "//CcyNtry[${index}]/CcyNm" < "${LIST_FILENAME}")
|
|
declare code=$(xmlstarlet sel --template --value-of "//CcyNtry[${index}]/Ccy" < "${LIST_FILENAME}")
|
|
|
|
if [[ -z "${code}" ]]; then
|
|
continue
|
|
fi
|
|
|
|
echo " '${code}', //" $(sed --regexp-extended 's, +$,,' <<< "${name}")
|
|
done | sort --unique
|
|
sed --silent '/^ \]/,/^}/p' "${RULE_FILENAME}"
|
|
} > "${RULE_FILENAME_TEMPORARY}"
|
|
|
|
echo "- Updating content of '$(basename ${RULE_FILENAME})'"
|
|
mv "${RULE_FILENAME_TEMPORARY}" "${RULE_FILENAME}"
|
|
|
|
echo "Finished!"
|