Difference between revisions of "Module:NVR/data extraction tool"
Jump to navigation
Jump to search
blackwiki>Trappist the monk (create;) |
blackwiki>Trappist the monk (extract name;) |
||
| Line 6: | Line 6: | ||
local group; -- identify this collection of hull numbers | local group; -- identify this collection of hull numbers | ||
-- search for nvr links and associated 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 | + | for id, ltr, num, name in mw.ustring.gmatch (content, 'SHIPSDETAIL_([^%.]+)%.HTML\">(%a+)%s+(%d+).-_NameLink_%d\">([^<]+)') do |
| − | group = ltr; -- | + | table.insert (out_table, "[\'" .. ltr .. "-" .. num .."\'] = {\'" .. id .. "\', \'" .. name .. "\'}"); -- make table entries in wp hull number format |
| + | group = ltr; -- because ltr is local to the for loop | ||
end | end | ||
-- make pretty output | -- make pretty output | ||
Revision as of 13:18, 26 August 2017
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, name in mw.ustring.gmatch (content, 'SHIPSDETAIL_([^%.]+)%.HTML\">(%a+)%s+(%d+).-_NameLink_%d\">([^<]+)') do
table.insert (out_table, "[\'" .. ltr .. "-" .. num .."\'] = {\'" .. id .. "\', \'" .. name .. "\'}"); -- make table entries in wp hull number format
group = ltr; -- because 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;