Julia Pais Anal – Reliable & Fresh
# ---------------------------------------------------------------- # 4️⃣ Example usage # ---------------------------------------------------------------- if abspath(PROGRAM_FILE) == @__FILE__ # run only when this file is executed directly # Example: a tiny GDP table (USD per‑capita). In real life you would # load this from a CSV, an API, or a more complete dataset. sample_gdp = Dict( "FRA" => 41_463.0, "DEU" => 46_215.0, "JPN" => 40_247.0, "BRA" => 7_498.0, "USA" => 69_287.0 )
data = JSON3.read(String(resp.body))[1] # REST Countries returns an array; we take the first match julia pais anal
# ---------------------------------------------------------------- # 3️⃣ Core function: fetch + analyse # ---------------------------------------------------------------- """ analyze_country(name_or_code::AbstractString; gdp_table=nothing) using Printf # for nice formatting # ----
A lightweight container for the most relevant pieces of information about a country. """ struct CountryInfo name::String # common name official_name::String # official name iso2::String # ISO‑3166‑1 alpha‑2 code iso3::String # ISO‑3166‑1 alpha‑3 code population::Int64 area_km2::Float64 capital::VectorString region::String subregion::String languages::VectorString currencies::VectorString flag_url::String end add more fields
Wraps a `CountryInfo` together with some derived metrics. """ struct CountryReport info::CountryInfo density::Float64 # pop / km² gdp_per_capita::UnionMissing,Float64 economic_weight::UnionMissing,Float64 end
You can extend any of the steps (e.g., add more fields, plug in a different data source, or compute extra statistics). # -------------------------------------------------------------- # Country analysis feature for Julia # -------------------------------------------------------------- using HTTP using JSON3 using DataFrames # optional, only needed if you want tabular output using Statistics # for mean, median, etc. using Printf # for nice formatting
# ---- 2️⃣ Build the CountryInfo struct --------------------------- info = CountryInfo( get(data["name"], "common", "unknown"), get(data["name"], "official", "unknown"), get(data, "cca2", "??"), get(data, "cca3", "???"), get(data, "population", 0), get(data, "area", 0.0), get(data, "capital", String[]), get(data, "region", "unknown"), get(data, "subregion", "unknown"), languages_from_dict(get(data, "languages", Dict())), currencies_from_dict(get(data, "currencies", Dict())), get(data["flags"], "png", "") )
