Modul:Geo: Unterschied zwischen den Versionen

local smw = require("Modul:SMW")
K (HeikoBot verschob die Seite Modul:Geocode nach Modul:Geo, ohne dabei eine Weiterleitung anzulegen)
(local smw = require("Modul:SMW"))
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
local p = {}
local p = {}
local com = require("Modul:Common")
local com = require("Modul:Common")
local que = require("Modul:Queries")
local smw = require("Modul:SMW")
local str = require("Modul:String")
local str = require("Modul:String")


Zeile 75: Zeile 76:
elseif   hausnummer < 9 then plz = 90762 elseif hausnummer < 401 then plz = 90766 else plz = 90768 end -- ungerade H.nr.
elseif   hausnummer < 9 then plz = 90762 elseif hausnummer < 401 then plz = 90766 else plz = 90768 end -- ungerade H.nr.
else
else
local plz_ask = que.getValues(strasse, "PLZ", true) -- alle anderen Straßen haben nur eine PLZ, die auf deren Seite vemerkt ist
local plz_ask = smw.getValues(strasse, "PLZ", true) -- alle anderen Straßen haben nur eine PLZ, die auf deren Seite vemerkt ist
if #plz_ask == 1 then -- mehr als eine oder keine PLZ?
if #plz_ask == 1 then -- mehr als eine oder keine PLZ?
plz = plz_ask[1]
plz = plz_ask[1]
Zeile 85: Zeile 86:


function p.GetPLZList(frame)
function p.GetPLZList(frame)
local sep = frame.args.sep or ";"
return table.concat(p.getPLZList(), frame.args.sep or ";")
local plz_table = p.getPLZList()
local plz_list = str.list(plz_table, sep)
return plz_list
end
end


Zeile 98: Zeile 96:
-- mw.logObject(frame)
-- mw.logObject(frame)
local plz = ""
local plz = ""
local stadtteile = frame.args[1]
local stadtteile = frame.args[1] or ""
if not com.isEmpty(stadtteile) then
if stadtteile ~= "" then
local stadtteile = str.splitAndStrip(stadtteile, ";")
local stadtteile = str.splitAndStrip(stadtteile, ";")
plz = p.stadtteil2PLZ(stadtteile)
plz = p.stadtteil2PLZ(stadtteile)
plz = str.list(plz, ";")
plz = table.concat(plz, ";")
end
end
-- mw.log(plz)
-- mw.log(plz)
Zeile 111: Zeile 109:
-- gibt die Postleitzahlen der Stadtteile als table zurück
-- gibt die Postleitzahlen der Stadtteile als table zurück
local plz_table = {}
local plz_table = {}
if not com.isEmpty(stadtteile) then
if type(stadtteile) == "table" then
if type(stadtteile) == "table" then
for _, s in pairs(stadtteile) do
for _, s in pairs(stadtteile) do
for _, p in pairs(smw.getValues(s, "PLZ", true)) do -- p ist string
for _, p in pairs(que.getValues(s, "PLZ", true)) do -- p ist string
plz_table[tonumber(p)] = true -- diese Mechanik verhindert mehrfaches Einfügen der gleichen PLZ
plz_table[tonumber(p)] = true -- diese Mechanik verhindert mehrfaches Einfügen der gleichen PLZ
end
end
end
else
plz_table[tonumber(que.getValues(stadtteile, "PLZ", true)[1])] = true
end
end
elseif stadtteile ~= nil and stadtteile ~= "" then
plz_table[tonumber(smw.getValues(stadtteile, "PLZ", true)[1])] = true
end
end
-- mw.logObject(plz_table)
-- mw.logObject(plz_table)