Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/RonnieV/Wikidata
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 = {} -- an empty table local function test(qid, pid) statementstbl = mw.wikibase.getBestStatements( qid, pid ) local labels = "" for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype labels = labels .. "<br>" .. dtype if dtype == "time" then labels = labels .. " is a time-element with value" local time = v.mainsnak.datavalue.value.time labels = labels .. time end end return labels end local maanden = { [1] = "januari", [2] = "februari", [3] = "maart", [4] = "april", [5] = "mei", [6] = "juni", [7] = "juli", [8] = "augustus", [9] = "september", [10] = "oktober", [11] = "november", [12] = "december" } local function getmonthname(m) m = 1*m local s = type(maanden[m]) == "function" and maanden[m]() or maanden[m] or m .. m .. m return s end local function getitems(qid, pid) statementstbl = mw.wikibase.getBestStatements( qid, pid ) local result = {} for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype if dtype == "wikibase-item" then local id = v.mainsnak.datavalue.value.id local label = mw.wikibase.getLabel(id) local dtype = v.mainsnak.datatype link = mw.wikibase.getSitelink(id) if link == nil or link == "" then newlabel = label else if link == label then newlabel = "[[" .. label .. "]]" else newlabel = "[[" .. link .. "|" .. label .. "]]" end end elseif dtype == "time" then local time = v.mainsnak.datavalue.value.time local prec = v.mainsnak.datavalue.value.precision local y, m, d = string.match(time, "+(%d+)-(%d+)-(%d+)") newlabel = "" if prec >= 11 then newlabel = d .. " " end if prec >= 10 then newlabel = newlabel .. getmonthname(m) .. " " end if prec >= 9 then newlabel = newlabel .. y end end table.insert(result, newlabel) -- labels = labels .. "<br>" .. newlabel end -- return labels return table.concat(result, "<br>") end local function getlabel(pid) local label = mw.wikibase.getLabel( pid ) return label end local function getprops() local props = {} table.insert(props, "P735") table.insert(props, "P734") table.insert(props, "P19") table.insert(props, "P569") table.insert(props, "P106") table.insert(props, "P26") table.insert(props, "P570") return props end function p.getinfo(frame) local qid = frame.args.qid or "Q42" local props = getprops() local htmlTable = mw.html.create("table") :addClass("wikitable") local headerRow = htmlTable :tag("tr") headerRow :tag("th") :attr("colspan", "2") :wikitext("Wikidata for " .. getlabel(qid) ) for k,v in pairs(props) do local row = htmlTable:tag("tr") local cell = row:tag("td") cell:wikitext(getlabel(v)) local cell = row:tag("td") cell:wikitext(getitems(qid, v) ) end return htmlTable end function p.test(frame) local qid = frame.args.qid or "Q42" result = test(qid, "P570") return result end -- reizigersinformatie van een station local function getmostrecentdate(qid) statementstbl = mw.wikibase.getAllStatements( qid, 'P1373' ) local maxtime = '' for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype if dtype == "quantity" then local value = v.mainsnak.datavalue.value.amount local datum = mw.wikibase.renderSnaks( v.qualifiers.P585 ) local jaar = string.sub(datum, string.len(datum)-4) if jaar > maxtime then maxtime = jaar end end end return maxtime end local function getNMBStelling(qid, gezochtjaar) statementstbl = mw.wikibase.getAllStatements( qid, 'P1373' ) local aantaldoordeweek = '-' local aantalzaterdag = '-' local aantalzondag = '-' local labels = "" for k, v in ipairs(statementstbl) do local dtype = v.mainsnak.datatype if dtype == "quantity" then local amount = string.sub(v.mainsnak.datavalue.value.amount,2) local tv = v.qualifiers.P585 local datum = mw.wikibase.renderSnaks( tv ) local jaar = string.sub(datum, string.len(datum)-4) if jaar == gezochtjaar then local dag = v.qualifiers.P2894 local weekdag = mw.wikibase.renderSnaks( dag ) or '' if weekdag == 'work week' then aantaldoordeweek = amount else if weekdag == 'Saturday' then aantalzaterdag = amount else if weekdag == 'Sunday' then aantalzondag = amount end end end end end end labels = '{{NMBS Reizigerstellingen|' .. aantaldoordeweek ..'|' .. aantalzaterdag .. '|' .. aantalzondag .. '|' .. gezochtjaar .. '}}' return labels end function p.getvoyagers(frame) local qid = frame.args.qid or "Q601108" local date = getmostrecentdate(qid) local result = getNMBStelling(qid, date) return result 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:Sandbox/RonnieV/Wikidata/doc
(
edit
)