Example #1
0
static void _init(EWeather *eweather)
{
    Instance *inst = calloc(1, sizeof(Instance));
    eweather->plugin.data = inst;
    inst->weather = eweather;
    inst->count = 11;

    EWeather_Data *e_data = eweather_data_current_get(inst->weather);
    snprintf(e_data->city, sizeof(e_data->city),
            "Paris");
    snprintf(e_data->region, sizeof(e_data->region),
            "IDF");
    snprintf(e_data->country, sizeof(e_data->country),
            "FR");

    e_data = eweather_data_get(inst->weather, 1);
    snprintf(e_data->city, sizeof(e_data->city),
            "Paris");
    snprintf(e_data->region, sizeof(e_data->region),
            "IDF");
    snprintf(e_data->country, sizeof(e_data->country),
            "FR");

    e_data = eweather_data_get(inst->weather, 2);
    snprintf(e_data->city, sizeof(e_data->city),
            "Paris");
    snprintf(e_data->region, sizeof(e_data->region),
            "IDF");
    snprintf(e_data->country, sizeof(e_data->country),
            "FR");


    inst->check_timer = ecore_timer_add(0, _weather_cb_check, inst);
}
Example #2
0
    static Eina_Bool
_weather_cb_check(void *data)
{
    Instance *inst = data;
    EWeather_Data *e_data = eweather_data_current_get(inst->weather);
    _populate(e_data, inst->count);
    _populate(eweather_data_get(inst->weather, 1), (inst->count+1)%15);
    _populate(eweather_data_get(inst->weather, 2), (inst->count+2)%15);

    inst->count++;
    if(inst->count>15)
        inst->count = 0;

    eweather_plugin_update(inst->weather);

    ecore_timer_interval_set(inst->check_timer, 5);
    return EINA_TRUE;
}
Example #3
0
   static int
_parse(Instance *inst)
{
   char *needle;
   char location[1024];
   char day[1024];
   char date[1024];
   EWeather_Data *e_data = eweather_data_current_get(inst->weather);
   EWeather_Data *e_data_current;
   char code[1024];
   int i;

   location[0] = 0;

   if (!inst->buffer) return 0;

   //printf("%s\n", inst->buffer);

   needle = strstr(inst->buffer, "<city data=\"");
   if (!needle) goto error;
   needle+=12;
   sscanf(needle, "%[^\"]\"", e_data->city);

   needle = strstr(needle, "<current_date_time data=\"");
   if (!needle) goto error;
   needle+=25;
   sscanf(needle, "%[^+]+", date);

   needle = strstr(needle, "<condition data=\"");
   if (!needle) goto error;
   needle += 17;
   sscanf(needle, "%[^\"]\"", code);

   e_data->type = _weather_type_get(code);

   needle = strstr(needle, "<temp_f data=\"");
   if (!needle) goto error;
   needle+=14;
   sscanf(needle, "%lf\"", &(e_data->temp));

   needle = strstr(needle, "<day_of_week data=\"");
   if (!needle) goto error;
   needle += 19; 
   sscanf(needle, "%[^\"]\"", day);

   snprintf(e_data->date, 256, "%s %s", day, date);


   needle = strstr(needle, "<low data=\"");
   if (!needle) goto error;
   needle+=11;
   sscanf(needle, "%lf\"", &(e_data->temp_min));

   needle = strstr(needle, "<high data=\"");
   if (!needle) goto error;
   needle+=12;
   sscanf(needle, "%lf\"", &(e_data->temp_max));

   e_data_current = e_data;
   
   for(i=1; i<4; i++)
     {
	e_data = eweather_data_get(inst->weather, i);

	needle = strstr(needle, "<day_of_week data=\"");
	if (!needle) goto error;
	needle+= 19;
	sscanf(needle, "%[^\"]\"", e_data->date);

	needle = strstr(needle, "<low data=\"");
	if (!needle) goto error;
	needle+=11;
	sscanf(needle, "%lf\"", &(e_data->temp_min));

	needle = strstr(needle, "<high data=\"");
	if (!needle) goto error;
	needle+=12;
	sscanf(needle, "%lf\"", &(e_data->temp_max));

	e_data->temp = ( e_data->temp_min + e_data->temp_max ) / 2;

	needle = strstr(needle, "<condition data=\"");
	if (!needle) goto error;
	needle += 17;
	sscanf(needle, "%[^\"]\"", code);

	e_data->type = _weather_type_get(code);

	strcpy(e_data->country, e_data_current->country);
	strcpy(e_data->region, e_data_current->region);
	strcpy(e_data->city, e_data_current->city);
     }

   eweather_plugin_update(inst->weather);
   return 1;
error:
   //printf ("ERROR: Couldn't parse info\n");
   return 0;
}
Example #4
0
   static int
_parse(Instance *inst)
{
   char *needle;
   char location[1024];
   char day[1024];
   char date[1024];
   EWeather_Data *e_data = eweather_data_current_get(inst->weather);
   EWeather_Data *e_data_current;
   int code;

   location[0] = 0;

   if (!inst->buffer) return 0;

   //printf("%s\n", inst->buffer);
   needle = strstr(inst->buffer, "<yweather:location");
   if (!needle) goto error;

   needle = strstr(needle, "city=\"");
   if (!needle) goto error;
   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, "<pubDate>");
   if (!needle) goto error;
   needle += 9;
   sscanf(needle, "%[^<]<", e_data->date);


   needle = strstr(needle, "<yweather:condition");
   if (!needle) goto error;

   needle = strstr(needle, "code=\"");
   if (!needle) goto error;
   needle+=6;
   sscanf(needle, "%d\"", &code);

   e_data->type = _weather_type_get(code);

   needle = strstr(needle, "temp=\"");
   if (!needle) goto error;
   needle+=6;
   sscanf(needle, "%lf\"", &(e_data->temp));


   needle = strstr(needle, "<b>Forecast:</b><BR />");
   if (!needle) goto error;

   needle = strstr(needle, "High: ");
   if (!needle) goto error;
   needle+=6;
   sscanf(needle, "%lf ", &(e_data->temp_max));

   needle = strstr(needle, "Low: ");
   if (!needle) goto error;
   needle+=5;
   sscanf(needle, "%lf ", &(e_data->temp_min));

   e_data_current = e_data;

   /*printf("CITY %s\n", e_data->city);
   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);
   */

   //tomorrow
   e_data = eweather_data_get(inst->weather, 1);

   needle = strstr(needle, "<yweather:forecast day=\"");
   if (!needle) goto error;
   needle+=24;

   needle = strstr(needle, "<yweather:forecast day=\"");
   if (!needle) goto error;
   needle+=24;
   sscanf(needle, "%[^\"]\"", day);

   needle = strstr(needle, "date=\"");
   if (!needle) goto error;
   needle+=6;
   sscanf(needle, "%[^\"]\"", date);

   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=\"");
   if (!needle) goto error;
   needle+=6;
   sscanf(needle, "%d\"", &code);
   e_data->type = _weather_type_get(code);

   strcpy(e_data->country, e_data_current->country);
   strcpy(e_data->region, e_data_current->region);
   strcpy(e_data->city, e_data_current->city);


   eweather_plugin_update(inst->weather);
   return 1;
error:
   //printf ("ERROR: Couldn't parse info\n");
   return 0;
}