User Tools

Site Tools


script_owm

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_owm [2015/05/17 20:43]
jappie
script_owm [2015/05/21 11:27] (current)
jappie [OWM-load] improved timer
Line 6: Line 6:
   *  Link    : https://​plus.google.com/​+JappieToutenhoofd/​posts/​   *  Link    : https://​plus.google.com/​+JappieToutenhoofd/​posts/​
  
 +====== Script code ====== 
 +======= OWM-load =======
 <​code>​ <​code>​
 var data_refresh_interval_minutes = 60; var data_refresh_interval_minutes = 60;
Line 49: Line 50:
     if (repl == null){return;​};​     if (repl == null){return;​};​
     self.owm.forcast = JSON.parse(repl);​     self.owm.forcast = JSON.parse(repl);​
 +  }
     self.owm.timer = setTimeout(refreshOWM,​ 600000);     self.owm.timer = setTimeout(refreshOWM,​ 600000);
-}+}
  
 clearTimeout(self.owm.timer);​ clearTimeout(self.owm.timer);​
Line 57: Line 58:
 refreshOWM();​ refreshOWM();​
 </​code> ​ </​code> ​
 +======= OWM-example =======
 +<​code>​
 +if (self.owm == null)
 +{ var owm_script = LL.getScriptByName("​OWM-load"​);​
 +  if (owm_script == null)
 +  { alert( "Also import script '​OWM-load'​. \n This script depends on it.");
 +    return;
 +  };
 +  LL.runScript('​OWM-load',​ null);
 +};
 +if (self.owm.current == null)
 +{ LL.runScript('​OWM-load',​ null);
 +  alert("​Weather data requested, \n Tap again to update."​);​
 +  return;
 +};
 +
 +var i = LL.getEvent().getItem();​
 +var t = self.owm.current.main.temp.toFixed(1);​
 +var c = self.owm.current.weather[0].id;​
 +var ofset = 60000;
 +if (self.owm.current.dt < self.owm.current.sys.sunrise)
 +{ofset += 1000 }
 +if (self.owm.current.dt > self.owm.current.sys.sunset)
 +{ofset += 1000 }
 +var s=String.fromCharCode(ofset + c);
 +var d = self.owm.current.weather[0].description;​
 +var w = parseInt(self.owm.current.wind.deg);​
 +i.setLabel(w + " " + t + "C "+ s +" " + d,true);
 +
 +alert("​last updated: " + new Date(1000 * self.owm.current.dt));​
 +alert(JSON.stringify( self.owm.current));​
 +alert(JSON.stringify( self.owm.forcast));​
 +
 +var test = new Date(1000 * self.owm.forcast.list[9].dt);​
 +alert( "in 9 days it is: " + self.owm.days[test.getDay()] + " " + test.getDate() + " and " + self.owm.forcast.list[9].weather[0].main );
 +
 +</​code>​
script_owm.1431895381.txt.gz · Last modified: 2015/05/17 20:43 by jappie