Skip to content

Instantly share code, notes, and snippets.

@mmd-osm
Created August 12, 2022 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmd-osm/7ef5f6254d7b84e52473757ad133ddd9 to your computer and use it in GitHub Desktop.
Save mmd-osm/7ef5f6254d7b84e52473757ad133ddd9 to your computer and use it in GitHub Desktop.
-- <includeonly>
local p = {}
function resultsAsTable(events)
if (events == nil or events.data == nil) then
return
end
text = '{| class="wikitable" style="font-size:smaller"\n'
text = text .. '|+ OSM Events\n'
text = text .. '|-\n'
text = text .. '! Date\n'
text = text .. '! Title\n'
text = text .. '! Location\n'
text = text .. '! Venue\n'
for _, result in ipairs(events.data) do
local is_cancelled = ((result.cancelled == nil and false) or result.cancelled)
text = text .. '|-'
text = text .. '\n| ' .. result.date.human_short
text = text .. '\n| ' .. ((is_cancelled and '<s>') or '') .. '[' .. result.url .. ' ' .. mw.text.nowiki(result.name) .. ']' .. ((is_cancelled and '</s>') or '')
if result.location == nil then
text = text .. '\n| '
text = text .. '\n| '
else
text = text .. '\n| ' .. result.location.short
text = text .. '\n| ' .. ((result.location.venue == nil and "") or result.location.venue)
end
text = text .. '\n'
end
text = text .. '|}\n'
return text
end
function p.Events()
local events = mw.ext.externaldata.getWebData {
url = 'https://osmcal.org/api/v2/events/'
, data = 'data=__json'
, format = 'JSON'
}
return resultsAsTable(events)
end
return p
-- </includeonly>
@mmd-osm
Copy link
Author

mmd-osm commented Aug 12, 2022

Embedding:

<div style="padding: 0.5em 1em 0.5em 1em; border-radius: 0 0 0.2em 0.2em;">
<span style="font-size:smaller">
{{#invoke:PutModuleNameHere|Events}}
</span>
</div>

@mmd-osm
Copy link
Author

mmd-osm commented Aug 12, 2022

Renders as:

osmcal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment