Module:Historical: Difference between revisions

From Empire of Dragons
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 40: Line 40:




-- Main function to be invoked
function p.getReign(frame)
function p.getReign(frame)
   
     local year = tonumber(frame.args[1])
     local year = tonumber(frame.args[1])
     if not year then
     if not year then
Line 47: Line 47:
     end
     end
      
      
     local country = frame.args[2] or 'swedishmonarchs'
     local country = frame.args[2] or 'sweden'
     local data = loadData(country)
     local data = loadData(country)
     if data then
     if data then
         local events = {}
         local events = {}
         local reigning = nil
         local reigning = nil
        local previousReign = nil


         for _, entry in ipairs(data) do
         for _, entry in ipairs(data) do
Line 58: Line 59:
                     table.insert(events, entry.event)
                     table.insert(events, entry.event)
                 end
                 end
                if entry.reign_start and entry.reign_end and year >= entry.reign_start and year <= entry.reign_end then
                    reigning = entry
                elseif entry.reign_start and not entry.reign_end and year >= entry.reign_start then
                    reigning = entry
                end
             end
             end
             if entry.reign_start and entry.reign_end and year >= entry.reign_start and year <= entry.reign_end then
           
                 reigning = entry
             if entry.reign_start and year >= entry.reign_start then
             elseif entry.reign_start and not entry.reign_end and year >= entry.reign_start then
                 previousReign = entry
                 reigning = entry
             end
           
            if entry.reign_start and year < entry.reign_start then
                 break
             end
             end
         end
         end
 
       
        if previousReign then
            reigning = previousReign
        end
       
         if reigning then
         if reigning then
             table.insert(events, string.format("%s reigns.", reigning.king or reigning.queen))
             table.insert(events, string.format("In the year %d, %s reigns.", year, reigning.king or reigning.queen))
             table.insert(events, string.format("Currently reigning: %s (since %d)", reigning.king or reigning.queen, reigning.reign_start))
             table.insert(events, string.format("Currently reigning: %s (since %d)", reigning.king or reigning.queen, reigning.reign_start))
             if reigning.reign_end then
             if reigning.reign_end then

Latest revision as of 12:57, 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 : In the year 1950, King Gustav VI Adolf reigns.
Currently reigning: King Gustav VI Adolf (since 1950)
Reign ends: 1973

In Norway
In the year 1950, King Haakon VII reigns.
Currently reigning: King Haakon VII (since 1905)
Reign ends: 1957

In France
In the year 1760, King Louis XV reigns.
Currently reigning: King Louis XV (since 1715)
Reign ends: 1774

In Spain
King Juan Carlos I abdicates, King Felipe VI ascends the throne.
In the year 2014, King Felipe VI reigns.
Currently reigning: King Felipe VI (since 2014)
In the year 2014 :King Juan Carlos I abdicates, King Felipe VI ascends the throne.

In England
In the year 1962, Queen Elizabeth II reigns.
Currently reigning: Queen Elizabeth II (since 1952)
Reign ends: 2022
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


-- Main function to be invoked
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 'sweden'
    local data = loadData(country)
    if data then
        local events = {}
        local reigning = nil
        local previousReign = nil

        for _, entry in ipairs(data) do
            if entry.year == year then
                if entry.event then
                    table.insert(events, entry.event)
                end
            end
            
            if entry.reign_start and year >= entry.reign_start then
                previousReign = entry
            end
            
            if entry.reign_start and year < entry.reign_start then
                break
            end
        end
        
        if previousReign then
            reigning = previousReign
        end
        
        if reigning then
            table.insert(events, string.format("In the year %d, %s reigns.", year, reigning.king or reigning.queen))
            table.insert(events, string.format("Currently reigning: %s (since %d)", reigning.king or reigning.queen, reigning.reign_start))
            if reigning.reign_end then
                table.insert(events, string.format("Reign ends: %d", reigning.reign_end))
            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