Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Naval Vessel Register URL/data extraction tool
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
p = {} --[[-------------------------< N A M E _ C A S E >-------------------------------------------------------------- Make mixed case names from uppercase names: HARRY L GLUCKSMAN to Harry L Glucksman ]] local function name_case (name) local s = mw.text.trim (name or ''); -- no leading or trailing white space local words = mw.text.split (s, ' '); -- split the name at the spaces it there are any for i, s in ipairs (words) do -- for each 'word' of the name s = string.lower (s) -- make it lowercase words[i] = mw.getContentLanguage():ucfirst(s); -- then uppercase the the first character end s = table.concat (words, ' '); -- put the name back together words = mw.text.split (s, '\''); -- now handle apostrophes if any (O'Brien, etc) for i, s in ipairs (words) do words[i] = mw.getContentLanguage():ucfirst(s); end return table.concat (words, '\\\''); -- put the name back together and done end ----------------------------< N V R _ E X T R A C T >---------------------------------------------------------- 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_case (name) .. "\'}"); -- make table entries in wp hull number format group = ltr:gsub ('T%-(.+)', '%1'); -- because ltr is local to the for loop; also strip off the 'T-' prefix end -- make pretty output return "<br /><pre>	[\'" .. group .. "\'] = <br />		{<br />		" .. table.concat (out_table, ',<br />		') .. "<br />		},<br /></pre>"; end return p;
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Naval Vessel Register URL/data extraction tool/doc
(
edit
)