-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests and build process, test on latest and nightly (#105)
* Update tests and build process * Further updates to build process * Add pre-built currency data file * Update README (#106) * Update README - Add Pkg to Project.yoml - Fix path in build.jl - _currencies -> _currency_data in constructor - Add alldata() and change allsyms() -> allsymbols() - Add test of data length * Remove alldata() and add test >= 155 Co-authored-by: Eric Forgy <[email protected]>
- Loading branch information
1 parent
fcda4ea
commit 31b3981
Showing
9 changed files
with
295 additions
and
133 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
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 |
---|---|---|
|
@@ -2,12 +2,13 @@ name = "Currencies" | |
uuid = "0fd90b74-7c1f-579e-9252-02cd883047b9" | ||
license = "MIT" | ||
authors = ["Eric Forgy <[email protected]>", "ScottPJones <[email protected]>"] | ||
version = "0.13.0" | ||
version = "0.14.0" | ||
|
||
[extras] | ||
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
build = ["JSON3"] | ||
build = ["JSON3","Pkg"] | ||
test = ["Test"] |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
environment: | ||
matrix: | ||
- julia_version: 1 | ||
- julia_version: latest | ||
- julia_version: nightly | ||
|
||
platform: | ||
|
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 |
---|---|---|
@@ -1,32 +1,53 @@ | ||
import Pkg; Pkg.add("JSON3") # Just in case | ||
|
||
using JSON3 | ||
|
||
# Data obtained from https://datahub.io/core/country-codes | ||
inputname = joinpath(@__DIR__,"country-codes.json") | ||
outputname = joinpath(@__DIR__, "currencies.jl") | ||
const src = "https://pkgstore.datahub.io/core/country-codes/country-codes_json/data/471a2e653140ecdd7243cdcacfd66608/country-codes_json.json" | ||
|
||
inputname = joinpath(@__DIR__, "country-codes.json") | ||
outputname = joinpath(@__DIR__, "currency-data.jl") | ||
|
||
# First, check if currency-data.jl already exists | ||
isfile(outputname) && return | ||
|
||
# Only download the file from datahub.io if not already present | ||
if !isfile(inputname) | ||
println("Downloading currency data: ", src) | ||
download(src, inputname) | ||
end | ||
|
||
const country_list = open(io -> JSON3.read(io), inputname) | ||
|
||
const SymAlpha = Symbol("ISO4217-currency_alphabetic_code") | ||
const currency_list = Dict{String,Tuple{Int,Int,String}}() | ||
|
||
const SymCurr = Symbol("ISO4217-currency_alphabetic_code") | ||
const SymUnit = Symbol("ISO4217-currency_minor_unit") | ||
const SymName = Symbol("ISO4217-currency_name") | ||
const SymCode = Symbol("ISO4217-currency_numeric_code") | ||
|
||
function genfile(io) | ||
for country in country_list | ||
(symlist = country[SymAlpha]) === nothing && continue | ||
(abbrlist = country[SymCurr]) === nothing && continue | ||
(unitlist = country[SymUnit]) === nothing && continue | ||
(namelist = country[SymName]) === nothing && continue | ||
(codelist = country[SymCode]) === nothing && continue | ||
symbols = split(symlist, ',') | ||
currencies = split(abbrlist, ',') | ||
units = split(string(unitlist), ',') | ||
names = split(namelist, ',') | ||
codes = split(string(codelist), ',') | ||
|
||
for (symbol, unit, code, name) in zip(symbols, units, codes, names) | ||
length(symbol) != 3 && continue | ||
println(io,"""Currency(:$symbol,$unit,$code,"$name")""") | ||
for (curr, unit, code, name) in zip(currencies, units, codes, names) | ||
length(curr) != 3 && continue | ||
haskey(currency_list, curr) && continue | ||
currency_list[curr] = (parse(Int, unit), parse(Int, code), string(name)) | ||
end | ||
end | ||
println(io, "const _currency_data = Dict(") | ||
for (curr, val) in currency_list | ||
println(io, " :$curr => (Currency{:$curr}(), $(val[1]), $(lpad(val[2], 4)), \"$(val[3])\"),") | ||
end | ||
println(io, ")\n") | ||
end | ||
|
||
open(io -> genfile(io), outputname, "w") | ||
|
Oops, something went wrong.