cedric pushed a commit to branch master. http://git.enlightenment.org/enlightenment/modules/forecasts.git/commit/?id=949cc0f279eaad427c7732a2264308ec0d25d3e7
commit 949cc0f279eaad427c7732a2264308ec0d25d3e7 Author: Mariusz Bialonczyk <ma...@skyboo.net> Date: Wed Jul 6 14:05:09 2016 -0700 forecast: adapt to new YQL Weather API Reviewers: pawatzaza Reviewed By: pawatzaza Subscribers: pawatzaza Differential Revision: https://phab.enlightenment.org/D4132 Signed-off-by: Cedric BAIL <ced...@osg.samsung.com> --- src/e_mod_main.c | 95 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/src/e_mod_main.c b/src/e_mod_main.c index f2ddadb..4f4522d 100644 --- a/src/e_mod_main.c +++ b/src/e_mod_main.c @@ -56,7 +56,7 @@ struct _Instance struct { - char temp, distance[3], pressure[3], speed[4]; + char temp, distance[3], pressure[3], speed[5]; } units; struct @@ -370,8 +370,8 @@ _forecasts_config_item_get(const char *id) ci->id = eina_stringshare_add(id); ci->poll_time = 60.0; ci->degrees = DEGREES_C; - ci->host = eina_stringshare_add("xml.weather.yahoo.com"); - ci->code = eina_stringshare_add("BUXX0005"); + ci->host = eina_stringshare_add("query.yahooapis.com"); + ci->code = eina_stringshare_add("839722"); ci->show_text = 1; ci->popup_on_hover = 1; @@ -424,8 +424,8 @@ e_modapi_init(E_Module *m) ci = E_NEW(Config_Item, 1); ci->poll_time = 60.0; ci->degrees = DEGREES_C; - ci->host = eina_stringshare_add("xml.weather.yahoo.com"); - ci->code = eina_stringshare_add("BUXX0005"); + ci->host = eina_stringshare_add("query.yahooapis.com"); + ci->code = eina_stringshare_add("839722"); ci->id = eina_stringshare_add("0"); ci->show_text = 1; ci->popup_on_hover = 1; @@ -608,7 +608,7 @@ _forecasts_server_add(void *data, int type, void *event) else degrees = 'c'; - snprintf(forecast, sizeof(forecast), "/forecastrss?p=%s&u=%c", inst->ci->code, degrees); + snprintf(forecast, sizeof(forecast), "/v1/public/yql?q=select+%%2A+from+weather.forecast+where+woeid%%3D%s+and+u%%3D%%27%c%%27", inst->ci->code, degrees); snprintf(buf, sizeof(buf), "GET http://%s%s HTTP/1.1\r\n" "Host: %s\r\n" "Connection: close\r\n\r\n", @@ -665,6 +665,7 @@ _forecasts_parse(void *data) char *needle; char city[256]; char region[256]; + char *region_ptr; char location[512]; float visibility; int i; @@ -676,29 +677,33 @@ _forecasts_parse(void *data) return 0; /* Location */ - needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:location city="); + needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:location "); + if (!needle) goto error; + needle = strstr(needle, "city=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%255[^\"]\"", city); region[0] = '\0'; needle = strstr(needle, "region=\""); + if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%255[^\"]\"", region); + region_ptr = region; + //get rid of leading white space + if (region[0] = ' ') + region_ptr++; - if (strlen(region)) - snprintf(location, 512, "%s, %s", city, region); + if (strlen(region_ptr)) + snprintf(location, 512, "%s, %s", city, region_ptr); else snprintf(location, 512, "%s", city); eina_stringshare_replace(&inst->location, location); /* Units */ - needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:units temperature="); - if (!needle) - goto error; - needle = strstr(needle, "\""); - sscanf(needle, "\"%c\"", &inst->units.temp); + needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:units "); + if (!needle) goto error; needle = strstr(needle, "distance=\""); if (!needle) goto error; needle = strstr(needle, "\""); @@ -710,29 +715,37 @@ _forecasts_parse(void *data) needle = strstr(needle, "speed=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%3[^\"]\"", inst->units.speed); + sscanf(needle, "\"%4[^\"]\"", inst->units.speed); + needle = strstr(needle, "temperature=\""); + if (!needle) goto error; + needle = strstr(needle, "\""); + sscanf(needle, "\"%c\"", &inst->units.temp); /* Current conditions */ - needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:condition text="); + needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:condition "); if (!needle) goto error; - needle = strstr(needle, "\""); - sscanf(needle, "\"%255[^\"]\"", inst->condition.desc); needle = strstr(needle, "code=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%d\"", &inst->condition.code); + needle = strstr(needle, "date=\""); + if (!needle) goto error; + needle = strstr(needle, "\""); + sscanf(needle, "\"%51[^\"]\"", inst->condition.update); needle = strstr(needle, "temp=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%d\"", &inst->condition.temp); - needle = strstr(needle, "date=\""); + needle = strstr(needle, "text=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%51[^\"]\"", inst->condition.update); + sscanf(needle, "\"%255[^\"]\"", inst->condition.desc); /* Details */ /* Wind */ - needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:wind chill="); + needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:wind "); + if (!needle) goto error; + needle = strstr(needle, "chill=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%d\"", &inst->details.wind.chill); @@ -746,15 +759,12 @@ _forecasts_parse(void *data) sscanf(needle, "\"%d\"", &inst->details.wind.speed); /* Atmosphere */ - needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:atmosphere humidity="); + needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:atmosphere "); if (!needle) goto error; - needle = strstr(needle, "\""); - sscanf(needle, "\"%d\"", &inst->details.atmosphere.humidity); - needle = strstr(needle, "visibility=\""); + needle = strstr(needle, "humidity=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%f\"", &visibility); - inst->details.atmosphere.visibility = visibility; + sscanf(needle, "\"%d\"", &inst->details.atmosphere.humidity); needle = strstr(needle, "pressure=\""); if (!needle) goto error; needle = strstr(needle, "\""); @@ -763,9 +773,16 @@ _forecasts_parse(void *data) if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%d\"", &inst->details.atmosphere.rising); + needle = strstr(needle, "visibility=\""); + if (!needle) goto error; + needle = strstr(needle, "\""); + sscanf(needle, "\"%f\"", &visibility); + inst->details.atmosphere.visibility = visibility; /* Astronomy */ - needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:astronomy sunrise="); + needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:astronomy "); + if (!needle) goto error; + needle = strstr(needle, "sunrise=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%8[^\"]\"", inst->details.astronomy.sunrise); @@ -777,35 +794,37 @@ _forecasts_parse(void *data) /* Forecasts */ for (i = 0; i < FORECASTS; i++) { - needle = strstr(needle, "<yweather:forecast day="); + needle = strstr(needle, "<yweather:forecast "); + if (!needle) goto error; + needle = strstr(needle, "code=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%4[^\"]\"", inst->forecast[i].day); + sscanf(needle, "\"%d\"", &inst->forecast[i].code); needle = strstr(needle, "date=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%12[^\"]\"", inst->forecast[i].date); - needle = strstr(needle, "low=\""); + needle = strstr(needle, "day=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%d\"", &inst->forecast[i].low); + sscanf(needle, "\"%4[^\"]\"", inst->forecast[i].day); needle = strstr(needle, "high=\""); if (!needle) goto error; needle = strstr(needle, "\""); sscanf(needle, "\"%d\"", &inst->forecast[i].high); - needle = strstr(needle, "text=\""); + needle = strstr(needle, "low=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%255[^\"]\"", inst->forecast[i].desc); - needle = strstr(needle, "code=\""); + sscanf(needle, "\"%d\"", &inst->forecast[i].low); + needle = strstr(needle, "text=\""); if (!needle) goto error; needle = strstr(needle, "\""); - sscanf(needle, "\"%d\"", &inst->forecast[i].code); + sscanf(needle, "\"%255[^\"]\"", inst->forecast[i].desc); } return 1; error: - fprintf(stderr, "ERROR: Couldn't parse info from xml.weather.yahoo.com\n"); + fprintf(stderr, "ERROR: Couldn't parse info from %s\n", inst->ci->host); return 0; } @@ -820,7 +839,7 @@ _forecasts_converter(Instance *inst) inst->units.temp = 'C'; snprintf(inst->units.distance, 3, "km"); snprintf(inst->units.pressure, 3, "mb"); - snprintf(inst->units.speed, 4, "kph"); + snprintf(inst->units.speed, 5, "km/h"); } else if ((inst->units.temp == 'C') && (inst->ci->degrees == DEGREES_F)) { --