« Module:ZoteroItem » : différence entre les versions
Aller à la navigation
Aller à la recherche
Page créée avec « -- Module:ZoteroItem local p = {} -- Fonction principale : passez seulement itemKey function p.getItem(frame) local key = frame.args[1] if not key or key == "" then return "Erreur : veuillez fournir un itemKey (exemple : XNXIG5JQ)" end -- ID de votre groupe Zotero (modifiez-le si différent) local groupId = "4893620" -- Construction de l'URL complète vers l'API Zotero local url = mw.uri.encode( "https://api.zotero.org/groups/" .. grou... » |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
function p.getItem(frame) | function p.getItem(frame) | ||
local key = frame.args[1] | local key = frame.args[1] | ||
if not key or key == "" then | if not key or key == "" then | ||
return "Erreur : | return "Erreur : aucun itemKey fourni" | ||
end | end | ||
local groupId = frame.args.groupId or "4893620" | |||
local url = string.format( | |||
local groupId = "4893620" | "https://api.zotero.org/groups/%s/items/%s?format=json&include=data", | ||
mw.uri.encode(groupId), | |||
mw.uri.encode(key) | |||
local url = | |||
"https://api.zotero.org/groups/ | |||
) | ) | ||
local t, errs = mw.ext.externalData.getWebData{ | |||
local | url = url, | ||
url | |||
format = "JSON" | format = "JSON" | ||
} | } | ||
if errs then | if errs then | ||
return "Erreur | return "Erreur HTTP ou parsing : " .. table.concat(errs, "; ") | ||
end | |||
if not t then | |||
return "Aucun résultat, possible timeout ou erreur silencieuse" | |||
end | end | ||
if not t.__json then | |||
return "Résultat inattendu : " .. mw.text.jsonEncode(t) | |||
if not | |||
return " | |||
end | end | ||
local d = t.__json.data | |||
local d = | if not d then | ||
return "Aucun champ 'data' dans la réponse" | |||
if d | |||
end | end | ||
-- | -- traitement normal... | ||
end | end | ||
return p | return p | ||
Version du 12 juin 2025 à 17:11
La documentation pour ce module peut être créée à Module:ZoteroItem/doc
local p = {}
function p.getItem(frame)
local key = frame.args[1]
if not key or key == "" then
return "Erreur : aucun itemKey fourni"
end
local groupId = frame.args.groupId or "4893620"
local url = string.format(
"https://api.zotero.org/groups/%s/items/%s?format=json&include=data",
mw.uri.encode(groupId),
mw.uri.encode(key)
)
local t, errs = mw.ext.externalData.getWebData{
url = url,
format = "JSON"
}
if errs then
return "Erreur HTTP ou parsing : " .. table.concat(errs, "; ")
end
if not t then
return "Aucun résultat, possible timeout ou erreur silencieuse"
end
if not t.__json then
return "Résultat inattendu : " .. mw.text.jsonEncode(t)
end
local d = t.__json.data
if not d then
return "Aucun champ 'data' dans la réponse"
end
-- traitement normal...
end
return p