Module:ImportRaces: Difference between revisions
Appearance
Sonja says (talk | contribs) No edit summary |
Sonja says (talk | contribs) No edit summary |
||
| Line 2: | Line 2: | ||
function p.import() | function p.import() | ||
local csvFile = mw.title.new("File:utopia_race_details.csv") | -- Load the CSV file from the specified folder | ||
local content = csvFile:getContent() | local csvFile = mw.title.new("File:uploads/utopia_race_details.csv") -- Adjust the path as necessary | ||
local lines = mw.text.split(content, "\n") | local content = csvFile:getContent() -- Get the content of the file | ||
local lines = mw.text.split(content, "\n") -- Split the content into lines | |||
for i, line in ipairs(lines) do | for i, line in ipairs(lines) do -- Loop through each line in the CSV | ||
if i > 1 then -- Skip header line | if i > 1 then -- Skip header line (the first line) | ||
local fields = mw.text.split(line, ",") | local fields = mw.text.split(line, ",") -- Split the line into fields | ||
local race = fields[1] | local race = fields[1] -- First field: race name | ||
local bonuses = fields[2] | local bonuses = fields[2] -- Second field: bonuses | ||
local penalties = fields[3] | local penalties = fields[3] -- Third field: penalties | ||
local unique = fields[4] | local unique = fields[4] -- Fourth field: unique features | ||
local spells = fields[5] | local spells = fields[5] -- Fifth field: spells | ||
-- Here, you would use Cargo's #cargo_insert_data to insert the data | |||
mw.log("Inserting race: " .. race) -- Log the race being inserted | |||
--[[ | |||
{{#cargo_insert_data: | {{#cargo_insert_data: | ||
| table = races | | table = races | ||
| Line 23: | Line 27: | ||
| spells = spells | | spells = spells | ||
}} | }} | ||
]] -- Pseudo-code for inserting data into Cargo | |||
end | end | ||
end | end | ||
Revision as of 13:01, 6 November 2025
local p = {}
function p.import()
-- Load the CSV file from the specified folder
local csvFile = mw.title.new("File:uploads/utopia_race_details.csv") -- Adjust the path as necessary
local content = csvFile:getContent() -- Get the content of the file
local lines = mw.text.split(content, "\n") -- Split the content into lines
for i, line in ipairs(lines) do -- Loop through each line in the CSV
if i > 1 then -- Skip header line (the first line)
local fields = mw.text.split(line, ",") -- Split the line into fields
local race = fields[1] -- First field: race name
local bonuses = fields[2] -- Second field: bonuses
local penalties = fields[3] -- Third field: penalties
local unique = fields[4] -- Fourth field: unique features
local spells = fields[5] -- Fifth field: spells
-- Here, you would use Cargo's #cargo_insert_data to insert the data
mw.log("Inserting race: " .. race) -- Log the race being inserted
--[[
{{#cargo_insert_data:
| table = races
| race = race
| bonuses = bonuses
| penalties = penalties
| unique = unique
| spells = spells
}}
]] -- Pseudo-code for inserting data into Cargo
end
end
end
return p