Module:DynamicYSWSList: Difference between revisions
U080F22CTJN (talk | contribs) does this work |
U080F22CTJN (talk | contribs) gorkie's hope for a fix |
||
| Line 2: | Line 2: | ||
function p.fetchlist(frame) | function p.fetchlist(frame) | ||
local data, errors = mw.ext.externalData.getExternalData{ | |||
url = 'https://hackclub.com/api/v1/events', | |||
format = 'json with jsonpath', | |||
data = 'name=$.data[*].name,description=$.data[*].description,' | |||
.. 'link=$.data[*].url,date=$.data[*].startDate' | |||
} | } | ||
if not data or #data == 0 then | if not data or #data == 0 then | ||
local msg = '<span class="error">Error fetch failed</span>' | |||
if errors and #errors > 0 then | |||
msg = msg .. '<br>(' .. table.concat(errors, '; ') .. ')' | |||
end | |||
return msg | |||
end | end | ||
local | local rows = { '=== All Hack Club Events ===' } | ||
for _, row in ipairs(data) do | |||
table.insert(rows, string.format('* [%s %s] %s (%s)', | |||
row.link or '#', row.name or 'Untitled', row.description or '', row.date or '')) | |||
end | |||
return frame:preprocess(table.concat(rows, '\n')) | |||
end | end | ||
return p | return p | ||