Ces derniers jours, l'API qui renvoie le texte renvoie None, car il n'y aurait pas de Saint ces jours-ci dans son calendrier.
Alors je me suis dit, pourquoi ne pas afficher une citation à la place ?
J'ai trouvé un site sur Internet qui fait ceci : http://www.citation-du-jour.fr
J'ai modifié le script en conséquence, il fonctionne bien.
Code : Tout sélectionner
-- script_time_saint.lua
--
-- récupération du saint du jour ou d'une citation dans un capteur texte
local saint_text_idx = 115 -- idx du capteur texte
local theme = 'humour'
function os.capture(cmd)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
return s
end
commandArray = {}
time = os.date("*t")
-- Trigger at 00:10
if (time.hour == 0 and time.min == 1) then
-- Path to curl
local curl = '/usr/bin/curl'
local cmd = curl .. ' http://domogeek.entropialux.com/feastedsaint/now'
local saint = os.capture(cmd);
if (saint ~= "None") then
-- Update device idx with nValue and sValue
commandArray['UpdateDevice'] = saint_text_idx .. '|0|Saints du jour ' .. saint
else
cmd = curl .. ' http://www.citation-du-jour.fr/apis/export.php?theme=' .. theme
local citation = os.capture(cmd);
-- Récupération de la citation
-- La chaîne renvoyée est par exemple : var q="“L\'ennemi est bête : il croit que c\'est nous l\'ennemi alors que c\'est lui !”";
-- var n="Pierre Desproges";
local QOTD = string.sub(citation, string.find(citation, '“'), string.find(citation,'”') + 5)
QOTD = string.gsub(QOTD, '\\', '')
QOTD = string.gsub(QOTD, ' ', ' ')
local auteur = string.gsub(string.sub(citation, string.find(citation, 'var n="') + 7, string.find(citation, '";', string.find(citation, 'var n="')) - 1), ' ', ' ')
print(string.gsub(QOTD.. auteur, ' ', ' '))
commandArray['UpdateDevice'] = saint_text_idx .. '|0|' .. QOTD .. ' ' .. auteur
end
end
return commandArray
Sur mon pc à base de i5 ça marchotte, mais sur la tablette 7" qui me sert pour Domoticz, ça pompe trop de ressources...
Je cherche encore, mais si vous avez des idées je suis preneur.