Dzvents : horoscope V2

Après la version 1 en lua voici la V2 en Dzvents
le principe est le même :
Le script vérifie toutes les x heures les horoscopes du site astro.rtl.fr signe par signe et mets à jour les éventuels devices texte associés sur domoticz


Le texte est tronqué à ~ 240 caractères pour ne pas surcharger l’affichage. Les caractères html sont convertis


--[[
name : script_time_horoscope.lua
auteur : papoo
Mise à jour : 30/03/2020
Création : 26/06/2016 =>V1.x https://github.com/papo-o/domoticz_scripts/blob/master/Lua/script_time_horoscope.lua
Dzvents : horoscope V2
https://easydomoticz.com/forum/viewtopic.php?f=17&t=9786 github : https://github.com/papo-o/domoticz_scripts/horoscope.lua Principe : Ce script a pour but de remonter les informations du site https://astro.rtl.fr/horoscope-jour-gratuit/ dans un device texte sur domoticz pour un signe donné et de nous alerter le cas échéant selon le niveau de notification choisi Fil de discussion : https://easydomoticz.com/forum/viewtopic.php?f=17&t=2176&p=34662#p34662 https://github.com/papo-o/domoticz_scripts/blob/master/Lua/script_time_horoscope.lua ]]-- local les_horoscopes = { { device = 'Horoscope 1', signe = 'belier'}, { device = 'Horoscope 2', signe = 'capricorne'}, { device = 'Horoscope 3', signe = 'vierge'}, { device = 'Horoscope 4', signe = 'balance'}, } local site_url = 'https://astro.rtl.fr/horoscope-jour-gratuit' -- url -------------------------------------------- ----------- Fin variables à éditer --------- -------------------------------------------- local scriptName = 'Horoscope' local scriptVersion = '2.01' return { active = true, on = { timer = { 'every 6 hours' },--https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting#timer_trigger_rules httpResponses = { 'belier','taureau','gemeaux','cancer','lion','vierge','balance','scorpion','sagittaire','capricorne','verseau','poissons' } -- Trigger --httpResponses = { 'cancer','capricorne' } -- Trigger }, logging = { level = domoticz.LOG_DEBUG, -- Seulement un niveau peut être actif; commenter les autres -- level = domoticz.LOG_INFO, -- Only one level can be active; comment others -- level = domoticz.LOG_ERROR, -- level = domoticz.LOG_MODULE_EXEC_INFO, marker = scriptName..' v'..scriptVersion }, execute = function(dz, item) local function logWrite(str,level) -- Support function for shorthand debug log statements dz.log(tostring(str),level or dz.LOG_DEBUG) end -------------------------------------------- local function TronquerTexte(texte, nb) -- texte à tronquer, Nb maximum de caractère local sep ="[?;!.]" local DernierIndex = nil texte = string.sub(texte, 1, nb) local p = string.find(texte, sep, 1) DernierIndex = p while p do p = string.find(texte, sep, p + 1) if p then DernierIndex = p end end return(string.sub(texte, 1, DernierIndex)) end -------------------------------------------- function unescape(str)--remplace le code html if (str) then local ascii = { [' '] =' ', ['¡'] ='¡', ['¢'] ='¢', ['£'] ='£', ['¤'] ='¤', ['¥'] ='¥', ['¦'] ='¦', ['§'] ='§', ['¨'] ='¨', ['©'] ='©', ['ª'] ='ª', ['«'] ='«', ['¬'] ='¬', ['­'] ='­', ['®'] ='®', ['¯'] ='¯', ['°'] ='°', ['±'] ='±', ['²'] ='²', ['³'] ='³', ['´'] ='´', ['µ'] ='µ', ['¶'] ='¶', ['·'] ='·', ['¸'] ='¸', ['¹'] ='¹', ['º'] ='º', ['»'] ='»', ['¼'] ='¼', ['½'] ='½', ['¾'] ='¾', ['¿'] ='¿', ['À'] ='À', ['Á'] ='Á', ['Â'] ='Â', ['Ã'] ='Ã', ['Ä'] ='Ä', ['Å'] ='Å', ['Æ'] ='Æ', ['Ç'] ='Ç', ['È'] ='È', ['É'] ='É', ['Ê'] ='Ê', ['Ë'] ='Ë', ['Ì'] ='Ì', ['Í'] ='Í', ['Î'] ='Î', ['Ï'] ='Ï', ['Ð'] ='Ð', ['Ñ'] ='Ñ', ['Ò'] ='Ò', ['Ó'] ='Ó', ['Ô'] ='Ô', ['Õ'] ='Õ', ['Ö'] ='Ö', ['×'] ='×', ['Ø'] ='Ø', ['Ù'] ='Ù', ['Ú'] ='Ú', ['Û'] ='Û', ['Ü'] ='Ü', ['Ý'] ='Ý', ['Þ'] ='Þ', ['ß'] ='ß', ['à'] ='à', ['á'] ='á', ['â'] ='â', ['ã'] ='ã', ['ä'] ='ä', ['å'] ='å', ['æ'] ='æ', ['ç'] ='ç', ['è'] ='è', ['é'] ='é', ['ê'] ='ê', ['ë'] ='ë', ['ì'] ='ì', ['í'] ='í', ['î'] ='î', ['ï'] ='ï', ['ð'] ='ð', ['ñ'] ='ñ', ['ò'] ='ò', ['ó'] ='ó', ['ô'] ='ô', ['õ'] ='õ', ['ö'] ='ö', ['÷'] ='÷', ['ø'] ='ø', ['ù'] ='ù', ['ú'] ='ú', ['û'] ='û', ['ü'] ='ü', ['ý'] ='ý', ['þ'] ='þ', ['ÿ'] ='ÿ', ['€'] ='€',['''] = "'" , ['"'] = '"', ['&']='&' } for code, char in pairs(ascii) do str = str:gsub(code, char ) end return str end end -------------------------------------------- if (item.isTimer) then for index,record in pairs(les_horoscopes) do-- On parcourt chaque horoscope device = record.device if device ~= nil and device ~= '' and dz.devices(device).name ~= nil then logWrite('--- --- --- traitement '..device..' --- --- --') signe = record.signe dz.openURL({--https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting#httpResponses url = site_url..'/'..signe, callback = signe }) end end --for end if (item.isHTTPResponse and item.ok) then logWrite('--- --- --- traitement --- --- --') for index,record in pairs(les_horoscopes) do-- On parcourt chaque horoscope device = record.device if dz.utils.deviceExists(record.device) then logWrite('--- --- --- traitement '..device..' --- --- --') signe = record.signe if item.trigger == signe then logWrite('--- --- --- traitement signe '..item.trigger..' --- --- --') for instance in item.data:gmatch("(.-)") do div, horoscope=instance:match('

En résumé

(.-)

(.-)

') end horoscope = TronquerTexte(unescape(horoscope), 240) logWrite(horoscope) dz.devices(record.device).updateText(horoscope or 'Pas d\'horoscope aujourd\'hui') end end end --for end end }

Suivez les dernières mises à jour de ce script



 Site Officiel :   sur Github

Laisser un commentaire