Module:Historical: Difference between revisions

From Empire of Dragons
Jump to navigation Jump to search
(Created page with "local p = {} -- Function to load the data from the subpage local function loadData(country) local success, data = pcall(function() return mw.loadData('Module:Historical/' .. country) end) if success then return data else return nil end end -- Main function to be invoked function p.getEvents(frame) local year = tonumber(frame.args[1]) if not year then return "No valid year specified." end local cou...")
 
No edit summary
Tag: Reverted
Line 36: Line 36:
     else
     else
         return "No data found for the specified country."
         return "No data found for the specified country."
    end
end
function p.getReign(frame)
    local year = tonumber(frame.args[1])
    if not year then
        return "No valid year specified."
    end
   
    local country = frame.args[2] or 'swedishmonarchs'
    local data = loadData(country)
    if data then
        local events = {}
        for _, event in ipairs(data) do
            if event.year == year then
                table.insert(events, event.event)
            end
            if event.reign_start and event.reign_end and year >= event.reign_start and year <= event.reign_end then
                table.insert(events, event.event)
            elseif event.reign_start and not event.reign_end and year >= event.reign_start then
                table.insert(events, event.event)
            end
        end
        if #events > 0 then
            return table.concat(events, '<br>')
        else
            return "No events found for the year " .. year .. " in " .. country .. "."
        end
    else
        return "No data found for the specified country: " .. country .. "."
     end
     end
end
end


return p
return p

Revision as of 07:58, 5 June 2024

Datafiles are in Historical/country


{{#invoke:Historical|getEvents|1990|[country]}}
{{#invoke:Historical|getReign|1950|[country]}}


In the year 1986 :Prime Minister Olof Palme is assassinated.

Swedish Kings : King Gustav V dies.

In Norway
No events found for the year 1950 in norway.

In France
No events found for the year 1760 in france.

In Spain
King Juan Carlos I abdicates, King Felipe VI ascends the throne.
In the year 2014 :King Juan Carlos I abdicates, King Felipe VI ascends the throne.

In England
The Cuban Missile Crisis occurs.
The Commonwealth Immigrants Act is passed.
The Beatles release their first single, 'Love Me Do'.
The James Bond film series begins with 'Dr. No'.
In the year 1962 :
The Cuban Missile Crisis occurs.
The Commonwealth Immigrants Act is passed.
The Beatles release their first single, 'Love Me Do'.
The James Bond film series begins with 'Dr. No'.


local p = {}

-- Function to load the data from the subpage
local function loadData(country)
    local success, data = pcall(function()
        return mw.loadData('Module:Historical/' .. country)
    end)
    if success then
        return data
    else
        return nil
    end
end

-- Main function to be invoked
function p.getEvents(frame)
    local year = tonumber(frame.args[1])
    if not year then
        return "No valid year specified."
    end
    
    local country = frame.args[2] or 'sweden'
    local data = loadData(country)
    if data then
        local events = {}
        for _, event in ipairs(data) do
            if event.year == year then
                table.insert(events, event.event)
            end
        end
        if #events > 0 then
            return table.concat(events, '<br>')
        else
            return "No events found for the year " .. year .. "."
        end
    else
        return "No data found for the specified country."
    end
end

function p.getReign(frame)
    local year = tonumber(frame.args[1])
    if not year then
        return "No valid year specified."
    end
    
    local country = frame.args[2] or 'swedishmonarchs'
    local data = loadData(country)
    if data then
        local events = {}
        for _, event in ipairs(data) do
            if event.year == year then
                table.insert(events, event.event)
            end
            if event.reign_start and event.reign_end and year >= event.reign_start and year <= event.reign_end then
                table.insert(events, event.event)
            elseif event.reign_start and not event.reign_end and year >= event.reign_start then
                table.insert(events, event.event)
            end
        end
        if #events > 0 then
            return table.concat(events, '<br>')
        else
            return "No events found for the year " .. year .. " in " .. country .. "."
        end
    else
        return "No data found for the specified country: " .. country .. "."
    end
end

return p