script sans erreur mais sans fonction
Publié : 03 févr. 2017, 11:46
Bonjour,
je suis partie sur un script trouvé sur ce site mais voila, il n'y a pas d'erreur dans les logs mais le script ne marche pas!
merci de vos conseils :
seb
je suis partie sur un script trouvé sur ce site mais voila, il n'y a pas d'erreur dans les logs mais le script ne marche pas!
merci de vos conseils :
Code : Tout sélectionner
--[[
auteur : stephdes
version : 1.0
MAJ : 12/12/2016
Principe :
Si mon "réveil" est activé, tous les matins à 7H une annonce avec température, météo, fête du jour... est diffusée sur un HP bluetooth de ma pièce de vie"
]]--
commandArray = {}
local timeNow= os.date("*t")
local curl='C:\\curl\\9\\bin\\curl.exe' --METTRE ICI LE CHEMIN DE VOTRE CURL
-- ############# REMISE A ZERO DE LA VARIABLE "BONJOUR" ENTRE 6H et 7H (la variable doit être de type chaîne) #################
if (timeNow.hour >=5 and timeNow.hour <6) then
commandArray['Variable:bonjour'] = tostring (0)
end
-- ############# CONDITIONS NECESSAIRES A L'EXECUTION DU SCRIPT #################
if devicechanged['annoncematin'] == "On" and
otherdevices['agenda google'] == 'On' and
uservariables["bonjour"] == '0'
then
local sentence="Bonjour ! Nous sommes le "..(os.date("%A")).." "..(os.date("%d")).." ".. os.date("%B").."."
local d = {
["Monday"] = " Lundi ",
["Tuesday"] = " Mardi ",
["Wednesday"] = " Mercredi ",
["Thursday"] = " Jeudi ",
["Friday"] = " Vendredi ",
["Saturday"] = " Samedi ",
["Sunday"] = " Dimanche ",
["01"] = " premier ",
["02"] = " deux ",
["03"] = " trois ",
["04"] = " quatre ",
["05"] = " cinq ",
["06"] = " six ",
["07"] = " sept ",
["08"] = " huit ",
["09"] = " neuf ",
["January"] = " Janvier ",
["February"] = " Février ",
["March"] = " Mars ",
["April"] = " Avril ",
["May"] = " Mai ",
["June"] = " Juin ",
["July"] = " Juillet ",
["August"] = " Août ",
["September"] = " Septembre ",
["October"] = " Octobre ",
["November"] = " Novembre ",
["December"] = " Décembre " }
for k, v in pairs (d) do
sentence = string.gsub(sentence, k, v)
end
-- ############# TEMPERATURE ET METEO #################
json = (loadfile "C:\\cURL\\9\\bin\\JSON.lua")() --METTRE ICI LE CHEMIN DU JSON
local city = "flagey-rigney"
local wuAPIkey = "XXXXXXXXXXX"
local file=assert(io.popen(curl.. 'http://api.wunderground.com/api/'..wuAPIkey..'/forecast/lang:FR/q/France/'..city..'.json'))
local raw = file:read('*all')
file:close()
local jsonForecast = json:decode(raw)
--prevision = jsonForecast.forecast.txt_forecast.forecastday[1].fcttext_metric -- Prévision complète
prevision=jsonForecast.forecast.simpleforecast.forecastday[1].conditions -- Prévision rapide
local t = {
["ºC"] = "degré",
[" ENE "] = " Est Nord Est ",
[" NNE "] = " Nord Nord Est ",
[" NE "] = " Nord Est ",
[" N "] = " Nord ",
[" NNO "] = " Nord Nord Ouest ",
[" NO "] = " Nord Ouest ",
[" SSE "] = " Sud Sud Est ",
[" SE "] = " Sud Est ",
[" S "] = " Sud ",
[" SSO "] = " Sud Sud Ouest ",
[" SO "] = " Sud Ouest ",
[" O "] = " Ouest ",
[" E "] = " Est ",
["km/h"] = " kilomètre heure" }
for k, v in pairs (t) do
prevision = string.gsub(prevision, k, v)
end
sentence=sentence.."Le temps de la journée sera "..prevision
-- ############# AJOUT RISQUE DE GIVRE #################
if (otherdevices_svalues['alerte givre'])=='Risque de givre' then
sentence=sentence.." Il y a peut etre du givre, soyez prudent."
elseif (otherdevices_svalues['Risque de givre'])=='Présence de givre !' then
sentence=sentence.." Attention il y a du givre, soyez très prudent!"
end
-- ############# AJOUT JOUR DES POUBELLES #################
month=tonumber(os.date("%m"))
day=tonumber(os.date("%d"))
-- TRash day : Mardi poubelle jaune (impair) / mardi poubelle verte (pair)
numOfWeek=tonumber(os.date("%V"))
numOfDay=os.date("%w")
if (numOfDay == '2') then -- mardi
if (numOfWeek % 2 ==0) then
sentence=sentence.."La poubelle verte est rammassé aujourd'hui." --pair
else
sentence=sentence.."La poubelle jaune est rammassé aujourd'hui." --impair
end
end
-- ############# PROGRAMME D'ENCODAGE DU TEXTE POUR LE TTS #################
function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
-- ############# ENCODAGE DU TTS #################
sentence = url_encode(sentence)
-- ############# SORTIE DU TEXTE #################
--print (sentence)
commandArray['OpenURL']="192.168.1.16:8888/?tts="..sentence..""
-- ############# PASSAGE DE LA VARIABLE BONJOUR A 1 POUR N'AVOIR LE MESSAGE QU'UNE SEULE FOIS PAR JOUR #################
commandArray['Variable:bonjour'] = tostring (1)
end
return commandArray