--
local function main local master = mw.loadData ("Module:Sandbox/trappist_the_monk/airports_convert/data")local _master = master._master
local out = ;local result = ;local cc_list =; for _, airport in ipairs (_master) do -- for each airport table in _master if not out[airport[1]] then -- if out does not have a table for the continent out[airport[1]] = ; -- make one end if not out[airport[1]][airport[2]] then -- if the continent table does not have a table for the country out[airport[1]][airport[2]] = -- make one end table.insert (out[airport[1]][airport[2]],); end
table.insert (result, '
master = {<br />') -- open master table table.insert (cc_list, '<pre>master = {<br />') -- open master table for continent_key, continent_table in pairs (out) do -- for each continent table in out{} table.insert (result, table.concat ({'	[\'', continent_key, '\'] = {<br />'})) -- write the index table.insert (cc_list, table.concat ({'	[\'', continent_key, '\'] = {<br />'})) -- write the index for country_key, country_table in pairs (continent_table) do -- for each country in continent_table{} table.insert (result, table.concat ({'		[\'', country_key, '\'] = {<br />'})); -- write the country index table.insert (cc_list, table.concat ({'		[\'', country_key, '\'],'})); -- write the country index for _, airport in ipairs (country_table) do -- for each airport in country_table{} local airport_table = {} -- create airport tables for i, v in ipairs (airport) do -- extract items from the airport table local item; if (3 > i) and ('' == v) then -- for IATA and ICAO codes item = table.concat ({'''', string.rep (' ', i+2)}); -- add enough spaces to make the tables pretty else item = table.concat ({''', v, '''}) -- numeric character entities to prevent empty string from being treated as italic markup end table.insert (airport_table, item); -- add the item to the airport table end table.insert (result, table.concat ({'			{', table.concat (airport_table, ', '), '},<br />'})) -- add the airport table to the country table end table.insert (result, '			},<br />'); -- close country table table.insert (cc_list, '<br />'); -- close country table end table.insert (result, '		},<br />'); -- close continnent table table.insert (cc_list, '		},<br />'); -- close continnent table end table.insert (result, '	};
return table.concat ('
--
local function duplicate_check local master = mw.loadData ("Module:IATA_and_ICAO_code/data/sandbox")local iata_count_table = ;local icao_count_table = ;
local _master = master._master
local iata = local icao =
for continent_key, continent_table in pairs (_master) do -- for each continent table in _master for country_key, country_table in pairs (continent_table) do -- for each country in continent_table for i, airport in ipairs (country_table) do -- for each airport table in country_table if ~= airport[1] then if not iata[airport[1]] then iata[airport[1]] = 1; -- state that this is the first time we've seen this code else iata[airport[1]] = iata[airport[1]] + 1; -- bump the count for this code end end if ~= airport[2] then if not icao[airport[2]] then icao[airport[2]] = 1; -- state that this is the first time we've seen this code else icao[airport[2]] = icao[airport[2]] + 1; -- bump the count for this code end end end end end
for k, v in pairs (iata) do if 1 < v then table.insert (iata_count_table, table.concat) end end
for k, v in pairs (icao) do if 1 < v then table.insert (icao_count_table, table.concat) end end local iata_msg = ; -- error messages go here local icao_msg = ;
if 0 ~= #iata_count_table then iata_msg = make_err_msg (err_msg['extra_iata'], table.concat (iata_count_table, ', '))-- iata_msg = table.concat end if 0 ~= #icao_count_table then icao_msg = make_err_msg (err_msg['extra_iata'], table.concat (icao_count_table, ', '))-- icao_msg = table.concat end if (0 ~= #iata_count_table) or (0 ~= #icao_count_table) then -- TODO find a better way of doing this return table.concat end return 'ok';end
return
;