Benutzer:Vegatello/Spielwiese/Modul:HoleArtikelKoordinaten

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

local p = {} --p stands for package

function p.getCoordinatesFromArticle( frame )

local givenArticleName = frame.args[1]
local givenCoordinatePart = frame.args[2]
local id = mw.wikibase.getEntityIdForTitle(givenArticleName)
local entity
local coordinateTable

if (id ~= nil and mw.wikibase.entityExists(id)) --will at least be nil when there's no article to the given articlename
then
 entity = mw.wikibase.getEntity(id)
 coordinateTable = entity:getBestStatements('P625')
 
 if (coordinateTable[1] ~= nil) --will be nil when property P625 isn't set
 then
  if (givenCoordinatePart == "ns")
  then
   return coordinateTable[1]["mainsnak"]["datavalue"]["value"]["latitude"]
  end
  if (givenCoordinatePart == "ew")
  then
   return coordinateTable[1]["mainsnak"]["datavalue"]["value"]["longitude"]
  end
 end
end

end

return p