Modul:Briefspielnews: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 11: | Zeile 11: | ||
--Hole die 500 neuesten Kapitel | --Hole die 500 neuesten Kapitel | ||
function holeKapitel(anzahl) | function holeKapitel(anzahl,alter) | ||
local kapitel=mw.smw.ask("{{#ask: [[-has subobject::+]]" | local mindat=os.time(); | ||
mindat.day=mindat.day-tonumber(alter) | |||
local kapitel=mw.smw.ask("{{#ask: [[-has subobject::+]] [[Kapiteldatum::>"..os.date("%Y-%m-%d",alter).."]]" | |||
.."|?#-=Kapitel" | .."|?#-=Kapitel" | ||
.."|?Kurzbeschreibung#" | .."|?Kurzbeschreibung#" | ||
Zeile 35: | Zeile 37: | ||
--Formatierung der Ausgabe | --Formatierung der Ausgabe | ||
function ausgabe(kapitel,alter) | function ausgabe(kapitel,alter,highlight) | ||
local alternum=tonumber(alter) | local alternum=tonumber(alter) | ||
local highlightnum=tonumber(highlight) | |||
local result="" | local result="" | ||
local now=os.time() | local now=os.time() | ||
Zeile 67: | Zeile 70: | ||
end | end | ||
local class="dunkel" | local class="dunkel" | ||
if diff> | if diff>highlightnum then | ||
class="hell" | class="hell" | ||
end | end | ||
Zeile 87: | Zeile 90: | ||
local alter=robusttrim(frame.args[2]) | local alter=robusttrim(frame.args[2]) | ||
if(alter=='') then anzahl='7' end | if(alter=='') then anzahl='7' end | ||
local kapitel=holeKapitel(anzahl) | local highlight=robusttrim(frame.args[3]) | ||
return ausgabe(kapitel,alter) | if(highlight=='') then anzahl='30' end | ||
local kapitel=holeKapitel(anzahl,alter) | |||
return ausgabe(kapitel,alter,highlight) | |||
end | end | ||
return p | return p |
Version vom 5. Oktober 2024, 13:24 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Briefspielnews/Doku erstellt werden
require("Modul:Hilfsfunktionen") require("Modul:Text") local p = {} --wandelt ein ISO-Datum in ein Time-Object um function parseISO(str) local y,m,d,h,i,s=str:match("(%d%d%d%d)-(%d?%d?)-(%d?%d?)T(%d?%d?):(%d?%d?):(%d?%d?)") return os.time({year=y,month=m,day=d,hour=h,min=i,sec=s}) end --Hole die 500 neuesten Kapitel function holeKapitel(anzahl,alter) local mindat=os.time(); mindat.day=mindat.day-tonumber(alter) local kapitel=mw.smw.ask("{{#ask: [[-has subobject::+]] [[Kapiteldatum::>"..os.date("%Y-%m-%d",alter).."]]" .."|?#-=Kapitel" .."|?Kurzbeschreibung#" .."|?Kapitelname ist" .."|?Reihe ist" .."|?Kapiteldatum#ISO" .."|limit="..anzahl .."|order=desc" .."|sort=Kapiteldatum" .."|offset=0" .."|searchlabel=") if kapitel==nil then return {} end return kapitel end --Sortierfunktion für die Reihen function sortReihe(t,a,b) return t[b]["Reihedatum"]<t[a]["Reihedatum"] end --Formatierung der Ausgabe function ausgabe(kapitel,alter,highlight) local alternum=tonumber(alter) local highlightnum=tonumber(highlight) local result="" local now=os.time() local reihe={} --Teile die Kapitel auf die Reihen auf for k,kap in spairs(kapitel) do kap["Datum"]=parseISO(kap["Kapiteldatum"]) local r=kap["Reihe ist"] if reihe[r]==nil then reihe[r]={} reihe[r]["Kapitel"]={} reihe[r]["Reihedatum"]=kap["Datum"] end table.insert(reihe[r]["Kapitel"],kap) if kap["Datum"]>reihe[r]["Reihedatum"] then reihe[r]["Reihedatum"]=kap["Datum"] end end --Gebe die Reihen aus for r,rei in spairs(reihe,sortReihe) do result=result.."\n==[["..r.." — Briefspielreihe|"..r.."]]==" result=result.."\n{| class=\"tabellehuebsch\" style=\"width:100%\"" for k,kap in spairs(rei["Kapitel"]) do local diff=os.difftime(now,kap["Datum"])/86400 local kurzbeschreibung=kap["Kurzbeschreibung"] if kurzbeschreibung==nil then kurzbeschreibung="" end local class="dunkel" if diff>highlightnum then class="hell" end result=result.."\n|- class=\""..class.."\"" result=result.."\n|style=\"width:10%\" class=\""..class.."\"|"..os.date("%Y-%m-%d",kap["Datum"]).." ("..diff.."/"..alternum..")" result=result.."\n|style=\"width:20%\" class=\""..class.."\"|[["..kap["Kapitel"].."|"..kap["Kapitelname ist"].."]]" result=result.."\n|style=\"width:70%\" class=\""..class.."\"|"..kurzbeschreibung end result=result.."\n|}" end return result end --Aufzurufende Funktion function p.news(frame) local anzahl=robusttrim(frame.args[1]) if(anzahl=='') then anzahl='10' end local alter=robusttrim(frame.args[2]) if(alter=='') then anzahl='7' end local highlight=robusttrim(frame.args[3]) if(highlight=='') then anzahl='30' end local kapitel=holeKapitel(anzahl,alter) return ausgabe(kapitel,alter,highlight) end return p