File tree 2 files changed +238
-97
lines changed
2 files changed +238
-97
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ # Usage: {script} TLD_FILENAME
3
+ # Update list of TLD
4
+
5
+ set -euo pipefail
6
+
7
+ declare -r IFS=$' \n '
8
+ declare -r URL=" https://www.currency-iso.org/dam/downloads/lists/list_one.xml"
9
+ declare -r RULE=" ${1} "
10
+ declare -r TEMPORARY_XML=$( mktemp)
11
+
12
+ download_list ()
13
+ {
14
+ echo " Downloading list from '${URL} '"
15
+ curl --silent --location " ${1} " --output " ${2} "
16
+ }
17
+
18
+ update_currency_codes ()
19
+ {
20
+ local -r filename_rule=" ${1} "
21
+ local -r filename_xml=" ${2} "
22
+ local -r number_of_items=$( grep " <CcyNtry>" " ${filename_xml} " | wc --lines)
23
+ local -r temporary_rule=$( mktemp)
24
+
25
+ echo " Updating list in '${filename_rule} '"
26
+ {
27
+ sed -n ' /^</,/ private/p' " ${filename_rule} "
28
+ for index in $( seq 1 ${number_of_items} ) ; do
29
+ local name=$( xml sel -t -v " //CcyNtry[${index} ]/CcyNm" < " ${filename_xml} " )
30
+ local code=$( xml sel -t -v " //CcyNtry[${index} ]/Ccy" < " ${filename_xml} " )
31
+ echo " '${code} ', // ${name} "
32
+ done
33
+ sed -n ' /^ ]/,/^}/p' " ${filename_rule} "
34
+ } > " ${temporary_rule} "
35
+
36
+ mv " ${temporary_rule} " " ${filename_rule} "
37
+ }
38
+
39
+ download_list " ${URL} " " ${TEMPORARY_XML} "
40
+ update_currency_codes " ${RULE} " " ${TEMPORARY_XML} "
You can’t perform that action at this time.
0 commit comments