|
Мітки: Очищення Ручний відкіт |
| (Не показані 54 проміжні версії цього користувача) |
| Рядок 1: |
Рядок 1: |
| local p = {}
| |
|
| |
|
| local TARGET_DATE_STR = "25.10.2024"
| |
| local TARGET_TIMESTAMP = os.time({year=2024, month=10, day=25, hour=0, min=0, sec=0})
| |
|
| |
| local function fetch_data_from_table(page_title, player_name, column_index)
| |
| local title = mw.title.new(page_title)
| |
| local content = title and title:getContent()
| |
|
| |
| if not content then
| |
| return nil
| |
| end
| |
|
| |
| local table_content = mw.ustring.match(content, "{|%s*class%s*=%s*\"wikitable\"(.-)|}")
| |
| if not table_content then
| |
| table_content = mw.ustring.match(content, "{|(.+?)|}")
| |
| end
| |
|
| |
| if not table_content then
| |
| return nil
| |
| end
| |
|
| |
| local escaped_player = mw.ustring.gsub(player_name, "([%(%)%.%-%+%[%]])", "%%%1")
| |
|
| |
| local player_link_pattern = "%[?%[" .. escaped_player .. "%]%]?"
| |
|
| |
| local row_pattern = "([|](.-)[|]%s*" .. player_link_pattern .. "(.-)[|])"
| |
| local row_match = mw.ustring.match(table_content, row_pattern)
| |
|
| |
| if not row_match then
| |
| return nil
| |
| end
| |
|
| |
| local columns = {}
| |
|
| |
| for value in mw.ustring.gmatch(row_match, "[|][^|]+") do
| |
| value = mw.ustring.gsub(value, "^|", "")
| |
| table.insert(columns, mw.text.trim(value))
| |
| end
| |
|
| |
| local result = columns[column_index]
| |
|
| |
| if result then
| |
| result = mw.text.trim(mw.ustring.gsub(result, "%[?%[?(.+)%]%]?", "%1"))
| |
| return result
| |
| else
| |
| return nil
| |
| end
| |
| end
| |
|
| |
| function p.date_added(frame)
| |
| local player = frame.args.player
| |
| local date_str = fetch_data_from_table("Гравці", player, 3)
| |
|
| |
| if not date_str or date_str == "" then
| |
| return "''Невідомо''"
| |
| end
| |
|
| |
| local day, month, year = mw.ustring.match(date_str, "(%d%d)%.(%d%d)%.(%d%d%d%d)")
| |
|
| |
| if not day then
| |
| return date_str .. " (Помилка формату)"
| |
| end
| |
|
| |
| local join_timestamp = os.time({year=tonumber(year), month=tonumber(month), day=tonumber(day), hour=0, min=0, sec=0})
| |
|
| |
| local diff_seconds = TARGET_TIMESTAMP - join_timestamp
| |
|
| |
| if diff_seconds < 0 then
| |
| return date_str
| |
| end
| |
|
| |
| local diff_days = math.floor(diff_seconds / 86400)
| |
|
| |
| return string.format("%s (%d д)", date_str, diff_days)
| |
| end
| |
|
| |
| function p.recruiter(frame)
| |
| local player = frame.args.player
| |
| local recruiter_name = fetch_data_from_table("Гравці", player, 4)
| |
|
| |
| if not recruiter_name or recruiter_name == "" or recruiter_name == "Не вказано" then
| |
| return "Не вказано"
| |
| end
| |
|
| |
| if mw.ustring.match(recruiter_name, "%[?%[?") then
| |
| return recruiter_name
| |
| else
| |
| return string.format("[[%s|%s]]", recruiter_name, recruiter_name)
| |
| end
| |
| end
| |
|
| |
| function p.prize_pool(frame)
| |
| local player = frame.args.player
| |
| local amount = fetch_data_from_table("Призовий_фонд", player, 3)
| |
|
| |
| if not amount or amount == "" then
| |
| return "0 ₴"
| |
| end
| |
|
| |
| amount = mw.ustring.gsub(amount, "[^%d%s]", "")
| |
| amount = mw.text.trim(amount)
| |
|
| |
| return amount .. " ₴"
| |
| end
| |
|
| |
| function p.foundation(frame)
| |
| local player = frame.args.player
| |
| local amount = fetch_data_from_table("Фундація", player, 3)
| |
|
| |
| if not amount or amount == "" then
| |
| return "0 ₴"
| |
| end
| |
|
| |
| amount = mw.ustring.gsub(amount, "[^%d%s]", "")
| |
| amount = mw.text.trim(amount)
| |
|
| |
| return amount .. " ₴"
| |
| end
| |
|
| |
| function p.final(frame)
| |
| local player = frame.args.player
| |
| local count = fetch_data_from_table("Фіналіст", player, 3)
| |
|
| |
| if not count or count == "" then
| |
| return "0/9"
| |
| end
| |
|
| |
| count = mw.ustring.match(count, "(%d+)")
| |
|
| |
| if not count then
| |
| return "0/9"
| |
| end
| |
|
| |
| return count .. "/9"
| |
| end
| |
|
| |
| return p
| |