imported>Legoktm
Replace Module:No globals with require( "strict" )
 
(No difference)

Latest revision as of 21:00, 23 October 2022

Documentation for this module may be created at Module:Sandbox/trappist the monk/ac code/doc

require('strict');
local p={}

function p.ac_code (frame)
	local page = mw.title.getCurrentTitle();									-- get a page object for this page
	local content = page:getContent();											-- get unparsed content
	local out_table = {};														-- table assembled tables
	local wiki_name;
	local icao;

	for iata, iata_name in string.gmatch (content, "p%.IATA%['(%u%u%u)'%]='([^\n\r]-)'") do	-- for each iata airport code line, get the code and airport name
		local temp_table = {};

		wiki_name = mw.ustring.match (content, "p%.WikiName%['" .. iata .. "'%]='([^\r\n]+)'");			-- get the wiki article name that matches iata code
		local name = mw.ustring.gsub (iata_name, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
		icao = mw.ustring.match (content, "p%.ICAO%['(%u%u%u%u)'%]='" .. name .. "'");				-- get the icao code that matches the iata airport name

		if not icao then icao = '' end
			
		table.insert (temp_table, '{');
		table.insert (temp_table, table.concat ({"'" .. iata .. "'", "'" .. icao .. "'", "'" .. mw.text.trim(iata_name) .. "'", "'" .. mw.text.trim(wiki_name) .. "'"}, ', '));
		table.insert (temp_table, '}');
		
		table.insert (out_table, table.concat (temp_table));
	end
	
	return "<br /><pre>return {<br />&#9;" .. table.concat (out_table, ',<br />&#9;') .. "<br />&#9;}<br />" .. "</pre>";
end

return p;