J'en ai profité pour le tweek un peu, désormais il prend également les catégorie amour santé travail et remplace les accent grave accent aigue ect qui seraient dans un format bizarre.horoscope général, amour,travail et sante se stockent tous dans un dummy idx différent, bien que la valeur amour soit récupérée je n'arrive pas encore a l'afficher cela dit. Je finirais bien par trouver ce qui cause ça, mais pour le reste c'est bon ^^
C'est codé de façon dégueulasse et j'imagine que mes 40 000 ligne de code peuvent s'ecrire en 2 mais... au moins ca marche
Code : Tout sélectionner
--[[
name : script_time_horoscope.lua
auteur : papoo
version : 1.10
Mise à jour : 27/06/2016 Changement de site
date : 26/06/2016
Principe :
Ce script a pour but de remonter les informations du site http://mon.astrocenter.fr/ dans un device texte
sur domoticz pour un signe donné et de nous alerter le cas écheant selon le niveau de notification choisi
]]--
-- ========================================================================
-- Variables à éditer
-- ========================================================================
local signe = "cancer" --[[ renseigner le signe choisi en minuscule sans accent : belier, taureau, gemeaux, cancer, lion, vierge,
balance, scorpion, sagittaire, capricorne, verseau, poissons ]]--
local dz_horoscope_general = 180 -- idx pour le texte general
local dz_horoscope_amour = 184 -- idx pour le texte d'amour
local dz_horoscope_travail = 182 -- idx pour le texte sur le travail
local dz_horoscope_sante = 183 -- idx pour le texte de santé
local send_notification = 0 -- 0: notifications désactivées, 1: notifications actives
local debugging = false -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
-- ========================================================================
-- Fin Variables à éditer
-- ========================================================================
local indexArray=0
-- ========================================================================
-- Fonctions
-- ========================================================================
function voir_les_logs (s)
if (debugging) then
print ("<font color='#f3031d'>".. s .."</font>");
end
end
function string:split( inSplitPattern, outResults )
if not outResults then
outResults = { }
end
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
-- ========================================================================
-- Fin Fonctions
-- ========================================================================
commandArray = {}
time = os.date("*t")
--if (time.hour == 00 and time.min == 20) then -- tout les matins à 00h20
if (time.min == 20 and ((time.hour == 7) or (time.hour == 13) or (time.hour == 18))) then -- 3 éxecutions du script par jour à 7H20, 13h20 et 18H20
-- if time.hour % 2 == 0 then -- toutes les deux heures
-- if (time.hour%1 == 0 and time.min == 10) then -- Toutes les heures et 10 minutes
-- if time.min % 2 == 0 then
print('script_time_horoscope.lua')
local fname ="horoscope.xml"
os.execute("wget -q -O " .. fname .. " http://astro.idf1.fr/horoscope/horoscope-du-jour/horoscope-"..signe.."/horoscope.html")
local f = io.open(fname, "r")
if f == nil then
print("Error opening file '" .. fname .. "'.")
os.exit(1)
end
local testHtml = f:read("*all")
f:close()
for instance in testHtml:gmatch("<body>(.-)</body>") do
horoscope=instance:match('Général</h2>(.-)</p>')
Amour=instance:match('Amour</h2>(.-)</p>')
Travail=instance:match('Travail</h2>(.-)</p>')
Sante=instance:match('/>Sant%é(.-)</p>')
horoscope=string.gsub(horoscope, "<p>", "Général : ")
horoscope=string.gsub(horoscope, "%'", " ")
horoscope=string.gsub(horoscope, "é", "é")
horoscope=string.gsub(horoscope, "ê", "ê")
horoscope=string.gsub(horoscope, "à", "à")
horoscope=string.gsub(horoscope, " ", " ")
horoscope=string.gsub(horoscope, "V", "v")
Amour=string.gsub(Amour, "<p>", "Amour : ")
Amour=string.gsub(Amour, "%'", " ")
Amour=string.gsub(Amour, "é", "é")
Amour=string.gsub(Amour, "ê", "ê")
Amour=string.gsub(Amour, "à", "à")
Amour=string.gsub(Amour, " ", " ")
Amour=string.gsub(Amour, "V", "v")
Amour=string.gsub(Amour, "A", "a")
Travail=string.gsub(Travail, "<p>", "Travail : ")
Travail=string.gsub(Travail, "%'", " ")
Travail=string.gsub(Travail, "é", "é")
Travail=string.gsub(Travail, "ê", "ê")
Travail=string.gsub(Travail, "à", "à")
Travail=string.gsub(Travail, " ", " ")
Travail=string.gsub(Travail, "V", "v")
Sante=string.gsub(Sante, "<p>", "Santé : ")
Sante=string.gsub(Sante, "%'", " ")
Sante=string.gsub(Sante, "é", "é")
Sante=string.gsub(Sante, "ê", "ê")
Sante=string.gsub(Sante, "à", "à")
Sante=string.gsub(Sante, " ", " ")
Sante=string.gsub(Sante, "V", "v")
end
if horoscope ~= nil and signe ~= nil then
voir_les_logs("--- --- --- ".. signe .." : ".. horoscope,debugging)
commandArray[indexArray] = {['UpdateDevice'] = dz_horoscope_general..'|0|'..horoscope}
indexArray=indexArray+1
commandArray[indexArray] = {['UpdateDevice'] = dz_horoscope_travail..'|0|'..Travail}
indexArray=indexArray+1
commandArray[indexArray] = {['UpdateDevice'] = dz_horoscope_sante..'|0|'..Sante}
indexArray=indexArray+1
commandArray[indexArray] = {['UpdateDevice'] = dz_horoscope_amour..'|0|'..Amour}
indexArray=indexArray+1
end
end -- if time
return commandArray