-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit will also create a Bash script to update that list in the future. Signed-off-by: Henrique Moody <[email protected]>
- Loading branch information
1 parent
c519316
commit 45d109f
Showing
2 changed files
with
238 additions
and
97 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
# Usage: {script} TLD_FILENAME | ||
# Update list of TLD | ||
|
||
set -euo pipefail | ||
|
||
declare -r IFS=$'\n' | ||
declare -r URL="https://www.currency-iso.org/dam/downloads/lists/list_one.xml" | ||
declare -r RULE="${1}" | ||
declare -r TEMPORARY_XML=$(mktemp) | ||
|
||
download_list() | ||
{ | ||
echo "Downloading list from '${URL}'" | ||
curl --silent --location "${1}" --output "${2}" | ||
} | ||
|
||
update_currency_codes() | ||
{ | ||
local -r filename_rule="${1}" | ||
local -r filename_xml="${2}" | ||
local -r number_of_items=$(grep "<CcyNtry>" "${filename_xml}" | wc --lines) | ||
local -r temporary_rule=$(mktemp) | ||
|
||
echo "Updating list in '${filename_rule}'" | ||
{ | ||
sed -n '/^</,/ private/p' "${filename_rule}" | ||
for index in $(seq 1 ${number_of_items}); do | ||
local name=$(xml sel -t -v "//CcyNtry[${index}]/CcyNm" < "${filename_xml}") | ||
local code=$(xml sel -t -v "//CcyNtry[${index}]/Ccy" < "${filename_xml}") | ||
echo " '${code}', // ${name}" | ||
done | ||
sed -n '/^ ]/,/^}/p' "${filename_rule}" | ||
} > "${temporary_rule}" | ||
|
||
mv "${temporary_rule}" "${filename_rule}" | ||
} | ||
|
||
download_list "${URL}" "${TEMPORARY_XML}" | ||
update_currency_codes "${RULE}" "${TEMPORARY_XML}" |
Oops, something went wrong.