devilhorns pushed a commit to branch master.

http://git.enlightenment.org/libs/libeweather.git/commit/?id=f88cb2c84deef63f84a12f7c0f6bb2e34fd4a22a

commit f88cb2c84deef63f84a12f7c0f6bb2e34fd4a22a
Author: Mariusz Bialonczyk <ma...@skyboo.net>
Date:   Wed Oct 5 14:51:48 2016 -0400

    libeweather: Fix the yahoo plugin, change to new public weather API
    
    cosmetics: fix format in the debug printf's
    
    Summary:
    Even this code is commented out, when somebody use it for debug
    purposes it will show zero values, as the format is wrong.
    
    The commit fixes this.
    
    yahoo: fix the plugin, use the new YQL weather API
    
    Yahoo returns its Weather API to public access again.
    This commit fixes the plugin to use this new API.
    Some changes were needed, eg the field order in the
    XML data changed slightly.
    
    More details:
    
https://www.igorkromin.net/index.php/2016/04/14/yahoo-returns-its-weather-api-to-public-access-switches-to-yql-for-query/
    
    Reviewers: devilhorns
    
    Subscribers: cedric, bu5hm4n
    
    Differential Revision: https://phab.enlightenment.org/D4128
---
 src/bin/eweather_test.c   |  9 +++++++++
 src/plugins/yahoo/yahoo.c | 51 +++++++++++++++++++++++------------------------
 2 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/src/bin/eweather_test.c b/src/bin/eweather_test.c
index b3198a0..35ceb24 100644
--- a/src/bin/eweather_test.c
+++ b/src/bin/eweather_test.c
@@ -98,6 +98,15 @@ int main(int argc, char **argv)
             eweather_plugin_set(eweather, m);
             break;
         }
+
+        // uncomment the following code to test the Yahoo plugin:
+        /* if(!strcmp(eweather_plugin_name_get(eweather, i), "Yahoo"))
+        {
+            eweather_plugin_set(eweather, m);
+            eweather_code_set(eweather, "791149");
+            eweather_temp_type_set(eweather, EWEATHER_TEMP_CELCIUS);
+            break;
+        }*/
     }
 
     evas_object_focus_set(ow, EINA_TRUE);
diff --git a/src/plugins/yahoo/yahoo.c b/src/plugins/yahoo/yahoo.c
index 8d6e6d9..a833fd0 100644
--- a/src/plugins/yahoo/yahoo.c
+++ b/src/plugins/yahoo/yahoo.c
@@ -117,7 +117,7 @@ static void _init(EWeather *eweather)
    Instance *inst = calloc(1, sizeof(Instance));
    eweather->plugin.data = inst;
    inst->weather = eweather;
-   inst->host = eina_stringshare_add("weather.yahooapis.com");
+   inst->host = eina_stringshare_add("query.yahooapis.com");
 
    ecore_con_init();
 
@@ -220,7 +220,7 @@ _server_add(void *data, int type, void *event)
    ev = event;
    if ((!inst->server) || (inst->server != ev->server)) return EINA_TRUE;
 
-   snprintf(buf, sizeof(buf), "GET http://%s/forecastrss?w=%s 
HTTP/1.1\r\nHost: %s\r\n\r\n",
+   snprintf(buf, sizeof(buf), "GET 
http://%s/v1/public/yql?q=select+%%2A+from+weather.forecast+where+woeid%%3D%s 
HTTP/1.1\r\nHost: %s\r\n\r\n",
         inst->host, inst->weather->code, inst->host);
    ecore_con_server_send(inst->server, buf, strlen (buf));
    return EINA_FALSE;
@@ -313,16 +313,16 @@ _parse(Instance *inst)
    needle+=6;
    sscanf(needle, "%[^\"]\"", e_data->city);
 
-   needle = strstr(needle, "region=\"");
-   if (!needle) goto error;
-   needle+=8;
-   sscanf(needle, "%[^\"]\"", e_data->region);
-
    needle = strstr(needle, "country=\"");
    if (!needle) goto error;
    needle+=9;
    sscanf(needle, "%[^\"]\"", e_data->country);
 
+   needle = strstr(needle, "region=\"");
+   if (!needle) goto error;
+   needle+=8;
+   sscanf(needle, "%[^\"]\"", e_data->region);
+
    needle = strstr(needle, "<pubDate>");
    if (!needle) goto error;
    needle += 9;
@@ -345,7 +345,7 @@ _parse(Instance *inst)
    sscanf(needle, "%lf\"", &(e_data->temp));
 
 
-   needle = strstr(needle, "<b>Forecast:</b><BR />");
+   needle = strstr(needle, "&lt;b&gt;Forecast:&lt;/b&gt;");
    if (!needle) goto error;
 
    needle = strstr(needle, "High: ");
@@ -364,23 +364,28 @@ _parse(Instance *inst)
    printf("REGION %s\n", e_data->region);
    printf("COUNTRY %s\n", e_data->country);
    printf("TYPE %d\n", e_data->type);
-   printf("TEMP %d\n", e_data->temp);
-   printf("TEMP MIN %d\n", e_data->temp_min);
-   printf("TEMP MAX %d\n", e_data->temp_max);
+   printf("TEMP %f\n", e_data->temp);
+   printf("TEMP MIN %f\n", e_data->temp_min);
+   printf("TEMP MAX %f\n", e_data->temp_max);
    */
 
    //tomorrow
    e_data = eweather_data_get(inst->weather, 1);
 
-   needle = strstr(needle, "<yweather:forecast day=\"");
+   needle = strstr(inst->buffer, "<yweather:forecast ");
    if (!needle) goto error;
-   needle+=24;
 
-   needle = strstr(needle, "<yweather:forecast day=\"");
+   needle = strstr(needle, "day=\"");
    if (!needle) goto error;
-   needle+=24;
+   needle+=5;
    sscanf(needle, "%[^\"]\"", day);
 
+   needle = strstr(needle, "code=\"");
+   if (!needle) goto error;
+   needle+=6;
+   sscanf(needle, "%d\"", &code);
+   e_data->type = _weather_type_get(code);
+
    needle = strstr(needle, "date=\"");
    if (!needle) goto error;
    needle+=6;
@@ -388,23 +393,17 @@ _parse(Instance *inst)
 
    snprintf(e_data->date, 256, "%s %s", day, date);
 
-   needle = strstr(needle, "low=\"");
-   if (!needle) goto error;
-   needle+=5;
-   sscanf(needle, "%lf\"", &(e_data->temp_min));
-
    needle = strstr(needle, "high=\"");
    if (!needle) goto error;
    needle+=6;
    sscanf(needle, "%lf\"", &(e_data->temp_max));
 
-   e_data->temp = ( e_data->temp_min + e_data->temp_max ) / 2;
-
-   needle = strstr(needle, "code=\"");
+   needle = strstr(needle, "low=\"");
    if (!needle) goto error;
-   needle+=6;
-   sscanf(needle, "%d\"", &code);
-   e_data->type = _weather_type_get(code);
+   needle+=5;
+   sscanf(needle, "%lf\"", &(e_data->temp_min));
+
+   e_data->temp = ( e_data->temp_min + e_data->temp_max ) / 2;
 
    strcpy(e_data->country, e_data_current->country);
    strcpy(e_data->region, e_data_current->region);

-- 


Reply via email to