Add day and date data_type to
authorCesare Tirabassi <norsetto@ubuntu.com>
Mon, 10 Aug 2009 20:46:21 +0000 (22:46 +0200)
committerCesare Tirabassi <norsetto@ubuntu.com>
Mon, 10 Aug 2009 20:46:21 +0000 (22:46 +0200)
ChangeLog
doc/variables.xml
src/weather.c
src/weather.h

index 7e9d08d..2c01546 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-08-10
+       * Add day and date data_type to $weather_forecast
+
 2009-08-03
        * Added support for $weather_forecast (experimental)
 
index 9759d62..661ce25 100644 (file)
             <para>'data_type' must be one of the following:</para>
             <simplelist>
                 <member>
+                    <command>day</command>
+                                       <option>Day of the week</option>
+                               </member>
+                <member>
+                    <command>date</command>
+                                       <option>Date, in the form MMM DD (ie. Jul 14)</option>
+                               </member>
+                <member>
                     <command>low</command>
                                        <option>Minimun temperature (you can use the
                     'temperature_unit' config setting to change
                     units)</option>
-               </member>
+                               </member>
                 <member>
                     <command>high</command>
                                        <option>Maximum temperature (you can use the
                     'temperature_unit' config setting to change
                     units)</option>
-               </member>
+                               </member>
                 <member>
                     <command>icon</command>
                     <option>Weather icon. Can be used together with the
                     icon kit provided upon registering to the weather.com
                     service</option>
-               </member>
+                               </member>
                 <member>
                     <command>forecast</command>
                     <option>Weather forecast (sunny, rainy, etc.)</option>
-               </member>
+                               </member>
                 <member>
                     <command>wind_speed</command>
                     <option>Wind speed in km/h</option>
index 4265a25..df4c3cb 100644 (file)
@@ -46,12 +46,13 @@ const char *xpath_expression_cc[NUM_XPATH_EXPRESSIONS_CC] = {
        "/weather/cc/hmid", "/weather/cc/icon"
 };
 
-#define NUM_XPATH_EXPRESSIONS_DF 8
+#define NUM_XPATH_EXPRESSIONS_DF 10
 const char *xpath_expression_df[NUM_XPATH_EXPRESSIONS_DF] = {
        "/weather/dayf/day[*]/hi", "/weather/dayf/day[*]/low",
        "/weather/dayf/day[*]/part[1]/icon", "/weather/dayf/day[*]/part[1]/t",
        "/weather/dayf/day[*]/part[1]/wind/s","/weather/dayf/day[*]/part[1]/wind/d",
-       "/weather/dayf/day[*]/part[1]/ppcp", "/weather/dayf/day[*]/part[1]/hmid"
+       "/weather/dayf/day[*]/part[1]/ppcp", "/weather/dayf/day[*]/part[1]/hmid",
+       "//@t", "//@dt"
 };
 #endif /* XOAP */
 
@@ -151,12 +152,21 @@ static void parse_df(PWEATHER_FORECAST *res, xmlXPathContextPtr xpathCtx)
                                        case 7:
                                                res->hmid[k] = atoi(content);
                                        }
-                                       xmlFree(content);
-                                       if (++k == FORECAST_DAYS) break;
+                               } else if (nodes->nodeTab[j]->type == XML_ATTRIBUTE_NODE) {
+                                       content = (char *)xmlNodeGetContent(nodes->nodeTab[k]);
+                                       switch(i) {
+                                       case 8:
+                                               strncpy(res->day[k], content, 8);
+                                               break;
+                                       case 9:
+                                               strncpy(res->date[k], content, 6);
+                                       }
                                }
+                               xmlFree(content);
+                               if (++k == FORECAST_DAYS) break;
                        }
-                       xmlXPathFreeObject(xpathObj);
                }
+               xmlXPathFreeObject(xpathObj);
        }
        return;
 }
@@ -683,6 +693,10 @@ void weather_forecast_process_info(char *p, int p_max_size, char *uri, unsigned
                snprintf(p, p_max_size, "%d", data->hmid[day]);
        } else if (strcmp(data_type, "precipitation") == EQUAL) {
                snprintf(p, p_max_size, "%d", data->ppcp[day]);
+       } else if (strcmp(data_type, "day") == EQUAL) {
+               strncpy(p, data->day[day], p_max_size);
+       } else if (strcmp(data_type, "date") == EQUAL) {
+               strncpy(p, data->date[day], p_max_size);
        }
 
        timed_thread_unlock(curloc->p_timed_thread);
index d70ec19..b1db019 100644 (file)
@@ -56,6 +56,8 @@ typedef struct PWEATHER_FORECAST_ {
        int low[FORECAST_DAYS];
        char icon[FORECAST_DAYS][3];
        char xoap_t[FORECAST_DAYS][32];
+       char day[FORECAST_DAYS][9];
+       char date[FORECAST_DAYS][7];
        int wind_s[FORECAST_DAYS];
        int wind_d[FORECAST_DAYS];
        int hmid[FORECAST_DAYS];