Module:NVR/data extraction tool
< Module:NVR
Jump to navigation
Jump to search
Revision as of 11:16, 26 August 2017 by blackwiki>Trappist the monk (create;)
This tool reads a local copy of an NVR web page to extract information required by Module:NVR.
To use this tool:
- open a blank sandbox page for editing – can be any page, there will be no need to save it unless you want to
- copy and paste this line into the sandbox:
{{#invoke:NVR/data extraction tool|nvr_extract}}
- in another browser window, open the NVR hull classification page for ships or service craft
- choose a hull classification symbol
- right-click and choose 'View page source'
- highlight and copy the entire html source to the clipboard and then paste the source into the sandbox below the line added at step 2
- click Show preview to run the tool
p = {}
function p.nvr_extract (frame)
local page = mw.title.getCurrentTitle(); -- get a page object for this page
local content = page:getContent(); -- get unparsed content
local out_table = {}; -- output goes here
local group; -- identify this collection of hull numbers
-- search for nvr links and associated hull numbers
for id, ltr, num in mw.ustring.gmatch (content, 'SHIPSDETAIL_([^%.]+)%.HTML\">(%a+)%s+(%d+)') do
table.insert (out_table, "[\'" .. ltr .. "-" .. num .."\'] = \'" .. id .. "\'"); -- make table entries in wp hull number format
group = ltr; -- becuase ltr is local to the for loop
end
-- make pretty output
return "<hr /><br /><pre>[\'" .. group .. "\'] = <br />	{<br />	" .. table.concat (out_table, ',<br />	') .. "<br />	}<br /></pre>";
end
return p;