Modul:ISO3166/loadData

Modul:ISO3166 loadData

Modul:ISO3166/loadData
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus

Dies ist die (produktive) Mutterversion eines global benutzten Lua-Moduls.
Wenn die serial-Information nicht übereinstimmt, müsste eine Kopie hiervon in das lokale Wiki geschrieben werden.
Versionsbezeichnung auf WikiData: 2019-10-13

local ISO3166 = { suite  = "ISO3166",
                  sub    = "loadData",
                  serial = "2019-10-13",
                  join   = 70862569,
                  main   = 69799761,
                  codes  = { } }
--[=[
Create ISO 3166 mw.loadData() table
]=]



local fetch = function ( achieve, alert )
    -- Retrieve data from Commons .tab JSON
    -- Precondition:
    --     achieve  -- string, with name of Commons tab
    --     alert    -- true, for throwing error on data problem
    -- Returns  table, with mapping string->string
    local storage = string.format( "ISO3166/%s.tab", achieve )
    local lucky, data = pcall( mw.ext.data.get, storage )
    local r = { }
    local s
    if type( data ) == "table"  and
       type( data.data ) == "table" then
        local entry, sign, set
        data = data.data
        for i = 1, #data do
            entry = data[ i ]
            if type( entry ) == "table" then
                sign = entry[ 1 ]
                if type( sign ) == "string" then
                    if r[ sign ] then
                        s = string.format( "Duplicated: %s (%d) @%s",
                                           sign, i, achieve )
                    else
                        set = entry[ 2 ]
                        if type( set ) == "string" then
                            r[ sign ] = set
                            if alert then
                                if mw.text.trim( sign ) ~= sign  or
                                   sign:upper() ~= sign  or
                                   sign == "" then
                                    s = string.format( "%s '%s' @%s",
                                                       "Bad key:",
                                                       sign, achieve )
                                end
                                if mw.text.trim( set ) ~= set  or
                                   set:upper() ~= set  or
                                   set == "" then
                                    s = string.format( "%s %s:'%s' @%s",
                                                       "Bad value:",
                                                       sign, set,
                                                       achieve )
                                end
                            end
                        else
                            s = string.format( "Invalid value: %s @%s",
                                               sign, achieve )
                        end
                    end
                else
                    s = string.format( "Bad entry (%d) @%s", i, achieve )
                end
            else
                s = string.format( "Invalid entry (%d) @%s", i, achieve )
            end
        end -- for i
    else
        s = "Missing or invalid page: commons:" .. storage
    end
    if s and alert then
        error( s, 0 )
    end
    return r
end -- fetch()



ISO3166.codes    = fetch( "codes" )
ISO3166.reverse  = fetch( "reverse" )
ISO3166.failsafe = ISO3166.serial



return ISO3166

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.