Module:Library: Difference between revisions
From Comprehensible Input Wiki
Content added Content deleted
No edit summary Tag: Reverted |
No edit summary |
||
(43 intermediate revisions by the same user not shown) | |||
Line 4:
if lang[1] then
local g = mw.ext.externaldata.getWebData {
url = 'https://comprehensibleinputwiki.com/
data = {
format = 'JSON'
}
Line 14:
}
tableOut = '
for key, value in ipairs(g) do
if not value['difficulty'] then
tableOut = tableOut .. '|- data-videoid="' .. value['id'] .. '" data-index="' .. value['index'] .. '"\n| ' .. mw.getCurrentFrame():callParserFunction( '#ev', 'youtube', value['id']) .. '\n| class="title"|' .. value['title'] .. '\n| ' .. value['level'] .. '\n| ' .. value['channel'] .. '\n| <div class="copy">Copy</div>\n| <div class="delete">Delete</div>\n| class="testing"|' .. math.random(500) .. '\n'▼
value['difficulty'] = "No Difficulty Set Yet"
end
if not value['difficulty_ordered'] then
value['difficulty_ordered'] = "0"
end
if not value['channel'] then
value['channel'] = "Missing Channel Name"
end
▲ tableOut = tableOut .. '
end
tableOut = tableOut .. '
return tableOut
else
|
Latest revision as of 16:35, 11 May 2023
Documentation for this module may be created at Module:Library/doc
local p = {}
function createTable(lang)
if lang[1] then
local g = mw.ext.externaldata.getWebData {
url = 'https://comprehensibleinputwiki.com/library.php?language=' .. lang[1],
data = {title, channel, id, index, difficulty, difficulty_ordered},
format = 'JSON'
}
local h = mw.ext.externaldata.getWebData {
url = tostring(mw.uri.fullUrl( 'Data:Mandarin Chinese/Videos' )) .. '?action=raw',
format = 'CSV with header'
}
tableOut = '<table id="library"><tr id="lib-header"><th>Video</th><th>Title</th><th>Difficulty</th><th>Channel</th></tr>'
for key, value in ipairs(g) do
if not value['difficulty'] then
value['difficulty'] = "No Difficulty Set Yet"
end
if not value['difficulty_ordered'] then
value['difficulty_ordered'] = "0"
end
if not value['channel'] then
value['channel'] = "Missing Channel Name"
end
tableOut = tableOut .. '<tr data-index="' .. value['main_index'] .. '"><td data-sort="' .. value['main_index'] .. '"> ' .. mw.getCurrentFrame():callParserFunction( '#ev', 'youtube', value['id']) .. '</td><td>' .. value['title'] .. '</td><td data-order="' .. value['difficulty_ordered'] .. '">' .. value['difficulty'] .. '</td><td>' .. value['channel'] .. '</td></tr>'
end
tableOut = tableOut .. '</table>'
return tableOut
else
return 'No language selected.'
end
end
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '\n['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
p.showLibrary = function(frame)
return createTable(frame:getParent().args)
end
return p