Pages

Labels

Sample (14) Intent (5) Media (5) Location (4) Funny (3) HTTP (3) Sleep as Android (3) WiFi (3) Alarm (2) Recording (2) Regexp (2) Array (1) Basic (1) Battery (1) Browser (1) Calculator (1) Contacts (1) Content Provider (1) Cron (1) Dialog (1) Dictionary (1) Export (1) Function (1) GUI (1) Game (1) Loop (1) Random (1) SD Card (1) Social (1) Temperature (1) Text to Speech (1) Weather (1)

Search Scripts

2013-05-19

Weather forecast by Taha

// timeout
r = waitForConnectivity(0);

beep(2000);

response = httpGet("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D1540935&format=json&callback=cbfunc");

speak("Attention : flash météo","french");

temp = find('"temp":"([0-9]+)"', response[1]);
tempC = round((number(temp[0])-32)*0.555);
humidity = find('"humidity":"([0-9]+)"', response[1]);

speed = find('"speed":"([0-9]+)"', response[1]);
speedKph = round(number(speed[0])/1.6);

windDirection = find('"direction":"([0-9]+)"', response[1]);

windL = "";
if(number(windDirection) > 285){
windL = "Nord ";
}
if(number(windDirection) < 75) {
windL = "Nord ";
} 
if(number(windDirection) < 255){
if(number(windDirection) > 105) {
windL = "Sud ";
}}
if(number(windDirection) > 45 ){
if(number(windDirection) < 135) {
windL = windL ~ "Est ";
}}
if(number(windDirection) < 325){
if(number(windDirection) > 225 ) {
windL = windL ~ "Ouest ";
}}

visibility = find('"visibility":"([0-9]+.[0-9]+)"', response[1]); 
visibilityKm = round( number(visibility[0])*1.6);
speak("La température à Tanger est "~tempC~" °C","french");
speak("L'humidité est de "~humidity[0]~"%","french");
speak("La vitesse du vent  est "~ speedKph~" Km/h en direction "~windL,"french");
speak("La visibilité est de "~ visibilityKm~" Km","french");

beep(2000);

3 comments:

  1. Check out YQL (Yahoo Query Language) for the woeid parameter related to the desired city.

    ReplyDelete
  2. Hello,
    Original script and idea.
    Seems however to be a bug in the script.
    Error message is :
    ERROR: Cannot run script Library: Weather forecast by Taha, IndexOutOfBoundsException Invalid index 0, size is 0.

    Please let me know if you find what the problem is.

    Using samsung galaxy note2. Android os 4.1.1 nor rooted.
    Imrana.thiam@gmail.com

    ReplyDelete
    Replies
    1. Sorry for the late reply. I no longer own an Android so I can't really test this. But I think if you remove "&callback=cbfunc" from the end of the URL it should be fine. Yahoo must have changed the output. I hope this helps.

      Delete