Модуль:Страны/data
Для документации этого модуля может быть создана страница Модуль:Страны/data/doc
--local flag_source_base = 'https://raw.githubusercontent.com/lipis/flag-icons/main/flags/4x3/'
local flag_source_base = 'https://upload.wikimedia.org/wikipedia/'
local country_data_url = 'https://raw.githubusercontent.com/esosedi/3166/master/countryList/ru.json'
local flag_list_url = 'https://raw.githubusercontent.com/ronatskiy/country-flags-svg/master/src/data/flagUrlByIso3.js'
local table_tools = require 'Module:TableTools'
local index, join, map = table_tools.index, table_tools.join, table_tools.map
local lc, external = mw.ustring.lower, mw.ext.externalData.getExternalData
local countries = external { url = country_data_url, format = 'json with jsonpath', data = {
iso2 = '$.*.iso'
, iso3 = '$.*.iso3'
, numeric = '$.*.numeric'
, fips = '$.*.fips'
, reference = '$.*.reference'
, name = '$.*.name'
} }
local flags = external {
url = flag_list_url
, format = 'text'
, regex = "/'(?<iso3>[A-Z]{3})':\\s*createUrl\\('(?<url>[^']+)'\\),/"
}
local data = map (join (countries, 'iso3', flags, 'iso3', true, true), function (record)
return {
iso2 = record.iso2
, iso3 = record.iso3
, fips = record.fips
, numeric = record.numeric
, reference = record.reference
, name = record.name
, svg_flag_url = record.url and flag_source_base .. record.url or nil
}
end)
local p = {}
local indices = { 'iso2', 'iso3', 'numeric', 'fips', 'name' }
for _, field in ipairs (indices) do
p [field] = index (data, field, true)
end
return p