source: titan/plugins/lcdpearl1/lcd_weather.h @ 18676

Last change on this file since 18676 was 18676, checked in by obi, 11 years ago

fix some plugin warnings

  • Property svn:executable set to *
File size: 12.8 KB
Line 
1
2struct stimerthread* weatherthread = NULL;
3
4struct weather
5{
6        char* city;
7        char* date;
8        char* day0;
9        char* day0_low;
10        char* day0_high;
11        char* day0_condition;
12        char* day0_icon;
13        char* day0_temp;
14        char* day0_humidity;
15        char* day0_wind;
16        char* day1;
17        char* day1_low;
18        char* day1_high;
19        char* day1_condition;
20        char* day1_icon;
21        char* day2;
22        char* day2_low;
23        char* day2_high;
24        char* day2_condition;
25        char* day2_icon;
26        char* day3;
27        char* day3_low;
28        char* day3_high;
29        char* day3_condition;
30        char* day3_icon;
31};
32
33void freeweather(struct weather* node)
34{
35        if(node == NULL) return;
36
37        free(node->city); node->city = NULL;
38        free(node->date); node->date = NULL;
39
40        free(node->day0); node->day0 = NULL;
41        free(node->day0_low); node->day0_low = NULL;
42        free(node->day0_high); node->day0_high = NULL;
43        free(node->day0_condition); node->day0_condition = NULL;
44        free(node->day0_icon); node->day0_icon = NULL;
45        free(node->day0_temp); node->day0_temp = NULL;
46        free(node->day0_humidity); node->day0_humidity = NULL;
47        free(node->day0_wind); node->day0_wind = NULL;
48
49        free(node->day1); node->day1 = NULL;
50        free(node->day1_low); node->day1_low = NULL;
51        free(node->day1_high); node->day1_high = NULL;
52        free(node->day1_condition); node->day1_condition = NULL;
53        free(node->day1_icon); node->day1_icon = NULL;
54
55        free(node->day2); node->day2 = NULL;
56        free(node->day2_low); node->day2_low = NULL;
57        free(node->day2_high); node->day2_high = NULL;
58        free(node->day2_condition); node->day2_condition = NULL;
59        free(node->day2_icon); node->day2_icon = NULL;
60
61        free(node->day3); node->day3 = NULL;
62        free(node->day3_low); node->day3_low = NULL;
63        free(node->day3_high); node->day3_high = NULL;
64        free(node->day3_condition); node->day3_condition = NULL;
65        free(node->day3_icon); node->day3_icon = NULL;
66
67        free(node); node = NULL;
68}
69
70struct weather* getweather(char* location)
71{
72        struct weather* weather = NULL;
73        char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL;
74        char* tmpsearch = NULL;
75
76        tmpsearch = ostrcat("data.aspx?weadegreetype=C&culture=de-DE&weasearchstr=", location, 0, 0);
77        //TODO: implement auto language (from titan.cfg)
78        //tmpsearch = ostrcat(tmpsearch, "&hl=de", 1, 0);
79//      tmpsearch = stringreplacechar(tmpsearch, ' ', '+');
80
81        tmpstr = gethttp("weather.service.msn.com", tmpsearch, 80, NULL, NULL, NULL, 0);
82
83        free(tmpsearch); tmpsearch = NULL;
84
85        if(tmpstr != NULL)
86        {
87                weather = (struct weather*)malloc(sizeof(struct weather));
88                if(weather == NULL)
89                {
90                        err("no mem");
91                        free(tmpstr); tmpstr = NULL;
92                        return NULL;
93                }
94                memset(weather, 0, sizeof(struct weather));
95
96                tmpstr1 = tmpstr;
97                tmpstr2 = tmpstr;
98
99                tmpstr2 = ostrstr(tmpstr1, "<weather weatherlocationcode=");
100                if(tmpstr2 != NULL)
101                {
102                        tmpstr1 = tmpstr2 + 5;
103                        weather->city = getxmlentry(tmpstr2, "weatherlocationname=");
104                }
105
106                tmpstr2 = ostrstr(tmpstr1, "<current ");
107                if(tmpstr2 != NULL)
108                {
109                        tmpstr1 = tmpstr2 + 5;
110                        weather->day0_temp = getxmlentry(tmpstr2, "temperature=");
111                        weather->date = getxmlentry(tmpstr2, "date=");
112                        weather->day0_humidity = getxmlentry(tmpstr2, "humidity=");
113                        weather->day0_wind = getxmlentry(tmpstr2, "windspeed=");
114                }
115               
116                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
117                if(tmpstr2 != NULL)
118                {
119                        tmpstr1 = tmpstr2 + 5;
120                        weather->day0_low = getxmlentry(tmpstr2, "low=");
121                        weather->day0_high = getxmlentry(tmpstr2, "high=");
122                        weather->day0_icon = getxmlentry(tmpstr2, "skycodeday=");
123                        weather->day0_condition = getxmlentry(tmpstr2, "skytextday=");
124                        weather->day0 = getxmlentry(tmpstr2, " shortday=");
125                }
126
127                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
128                if(tmpstr2 != NULL)
129                {
130                        tmpstr1 = tmpstr2 + 5;
131                        weather->day1_low = getxmlentry(tmpstr2, "low=");
132                        weather->day1_high = getxmlentry(tmpstr2, "high=");
133                        weather->day1_icon = getxmlentry(tmpstr2, "skycodeday=");
134                        weather->day1_condition = getxmlentry(tmpstr2, "skytextday=");
135                        weather->day1 = getxmlentry(tmpstr2, " shortday=");
136                }
137
138                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
139                if(tmpstr2 != NULL)
140                {
141                        tmpstr1 = tmpstr2 + 5;
142                        weather->day2_low = getxmlentry(tmpstr2, "low=");
143                        weather->day2_high = getxmlentry(tmpstr2, "high=");
144                        weather->day2_icon = getxmlentry(tmpstr2, "skycodeday=");
145                        weather->day2_condition = getxmlentry(tmpstr2, "skytextday=");
146                        weather->day2 = getxmlentry(tmpstr2, " shortday=");
147                }
148
149                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
150                if(tmpstr2 != NULL)
151                {
152                        tmpstr1 = tmpstr2 + 5;
153                        weather->day3_low = getxmlentry(tmpstr2, "low=");
154                        weather->day3_high = getxmlentry(tmpstr2, "high=");
155                        weather->day3_icon = getxmlentry(tmpstr2, "skycodeday=");
156                        weather->day3_condition = getxmlentry(tmpstr2, "skytextday=");
157                        weather->day3 = getxmlentry(tmpstr2, " shortday=");
158                }
159
160                free(tmpstr); tmpstr = NULL;
161        }
162
163        return weather;
164}
165
166char* changeweatherpic(char* icon)
167{
168
169                /*
170                0 => 'thunderstorm',
171                1 => 'thunderstorm',
172                2 => 'thunderstorm',
173                3 => 'thunderstorm',
174                4 => 'thunderstorm',
175                5 => 'rain_snow',
176                6 => 'sleet',
177                7 => 'rain_snow',
178                8 => 'icy',
179                9 => 'icy', 
180                10 => 'rain_snow',
181                11 => 'showers',
182                12 => 'rain',
183                13 => 'flurries',
184                14 => 'snow',
185                15 => 'snow',
186                16 => 'snow',
187                17 => 'thunderstorm',
188                18 => 'showers',
189                19 => 'dust',
190                20 => 'fog',
191                21 => 'haze',
192                22 => 'haze',
193                23 => 'windy',
194                24 => 'windy',
195                25 => 'icy',
196                26 => 'cloudy',
197                27 => 'mostly_cloudy',
198                28 => 'mostly_cloudy',
199                29 => 'partly_cloudy',
200                30 => 'partly_cloudy',
201                31 => 'sunny',
202                32 => 'sunny',
203                33 => 'mostly_sunny',
204                34 => 'mostly_sunny',
205                35 => 'thunderstorm',
206                36 => 'hot',
207                37 => 'chance_of_tstorm',
208                38 => 'chance_of_tstorm',
209                39 => 'chance_of_rain',
210                40 => 'showers',
211                41 - 'chance_of_snow', 
212                42 => 'snow',
213                43 => 'snow',
214                44 => 'na',
215                45 => 'chance_of_rain',
216                46 => 'chance_of_snow',
217                47 => 'chance_of_tstorm');
218                */
219       
220        char* node = NULL;
221        if(icon == NULL)
222                return node;
223
224        else if(ostrstr(icon, "10") != NULL)
225                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_snow60.png", 0, 0);
226        else if(ostrstr(icon, "11") != NULL)
227                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/showers60.png", 0, 0);
228        else if(ostrstr(icon, "12") != NULL)
229                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);           
230        else if(ostrstr(icon, "13") != NULL)
231                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/flurries60.png", 0, 0);       
232        else if(ostrstr(icon, "14") != NULL)
233                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/snow60.png", 0, 0);                   
234        else if(ostrstr(icon, "15") != NULL)
235                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/snow60.png", 0, 0);   
236        else if(ostrstr(icon, "16") != NULL)
237                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/snow60.png", 0, 0);   
238        else if(ostrstr(icon, "17") != NULL)
239                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
240        else if(ostrstr(icon, "18") != NULL)
241                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/showers60.png", 0, 0);       
242        else if(ostrstr(icon, "19") != NULL)
243                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/fog60.png", 0, 0);   
244        else if(ostrstr(icon, "20") != NULL)
245                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/fog60.png", 0, 0);   
246        else if(ostrstr(icon, "21") != NULL)
247                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/fog60.png", 0, 0);   
248        else if(ostrstr(icon, "22") != NULL)
249                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/fog60.png", 0, 0);   
250        else if(ostrstr(icon, "23") != NULL)
251                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_storm60.png", 0, 0);       
252        else if(ostrstr(icon, "24") != NULL)
253                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_storm60.png", 0, 0);       
254        else if(ostrstr(icon, "25") != NULL)
255                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/icy60.png", 0, 0);   
256        else if(ostrstr(icon, "26") != NULL)
257                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/cloudy60.png", 0, 0);
258        else if(ostrstr(icon, "27") != NULL)
259                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/partly_cloudy60.png", 0, 0); 
260        else if(ostrstr(icon, "28") != NULL)
261                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/partly_cloudy60.png", 0, 0);
262        else if(ostrstr(icon, "29") != NULL)
263                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/partly_cloudy60.png", 0, 0); 
264        else if(ostrstr(icon, "30") != NULL)
265                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/partly_cloudy60.png", 0, 0); 
266        else if(ostrstr(icon, "31") != NULL)
267                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/sunny60.png", 0, 0); 
268        else if(ostrstr(icon, "32") != NULL)
269                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/sunny60.png", 0, 0); 
270        else if(ostrstr(icon, "33") != NULL)
271                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/mostly_sunny60.png", 0, 0);   
272        else if(ostrstr(icon, "34") != NULL)
273                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/mostly_sunny60.png", 0, 0);                   
274        else if(ostrstr(icon, "35") != NULL)
275                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
276        else if(ostrstr(icon, "36") != NULL)
277                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/sunny60.png", 0, 0); 
278        else if(ostrstr(icon, "37") != NULL)
279                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_storm.png", 0, 0); 
280        else if(ostrstr(icon, "38") != NULL)
281                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_storm.png", 0, 0); 
282        else if(ostrstr(icon, "39") != NULL)
283                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_rain60.png", 0, 0);                 
284        else if(ostrstr(icon, "40") != NULL)
285                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/showers60.png", 0, 0);       
286        else if(ostrstr(icon, "41") != NULL)
287                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_snow60.png", 0, 0);
288        else if(ostrstr(icon, "42") != NULL)
289                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/snow60.png", 0, 0);                   
290        else if(ostrstr(icon, "43") != NULL)
291                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/snow60.png", 0, 0);   
292        else if(ostrstr(icon, "44") != NULL)
293                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/xxxx.png", 0, 0);     
294        else if(ostrstr(icon, "45") != NULL)
295                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_rain60.png", 0, 0);
296        else if(ostrstr(icon, "46") != NULL)
297                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_snow60.png", 0, 0);
298        else if(ostrstr(icon, "47") != NULL)
299                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_rain60.png", 0, 0);
300        else if(ostrstr(icon, "0") != NULL)
301                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
302        else if(ostrstr(icon, "1") != NULL)
303                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
304        else if(ostrstr(icon, "2") != NULL)
305                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
306        else if(ostrstr(icon, "3") != NULL)
307                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);
308        else if(ostrstr(icon, "4") != NULL)
309                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
310        else if(ostrstr(icon, "5") != NULL)
311                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_snow60.png", 0, 0);
312        else if(ostrstr(icon, "6") != NULL)
313                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/rain60.png", 0, 0);   
314        else if(ostrstr(icon, "7") != NULL)
315                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/chance_of_snow60.png", 0, 0);
316        else if(ostrstr(icon, "8") != NULL)
317                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/icy60.png", 0, 0);
318        else if(ostrstr(icon, "9") != NULL)
319                node = ostrcat(node, "%pluginpath%/lcdpearl1/skin/icy60.png", 0, 0);                           
320// fix warning
321        return node;
322}
323
324void lcd_writeweather()
325{
326       
327        char* tmpstr = NULL;
328        char* location = NULL;
329        struct weather* node = NULL;
330       
331        location = ostrcat(location, getconfig("lcd_pearl1_plugin_wetterort", NULL), 0, 0);
332        //location = ostrcat(location, getconfig("lcd_pearl1_plugin_wetterplz", NULL), 0, 0);
333        //location = ostrcat(location, "-", 1, 0);
334        //location = ostrcat(location, getconfig("lcd_pearl1_plugin_wetterland", NULL), 1, 0);
335
336        node = getweather(location);
337        free(location); location = NULL;
338
339        if(node != NULL)
340        {
341                FILE* ausg;
342                ausg=fopen("/tmp/lcdweather","w");
343
344                fprintf(ausg,"%s\n",node->date);
345                fprintf(ausg,"%s\n",node->day0);
346                fprintf(ausg,"%s\n",node->day0_low);
347                fprintf(ausg,"%s C\n",node->day0_high);
348                fprintf(ausg,"%s\n",node->day0_condition);
349                tmpstr = changeweatherpic(node->day0_icon);
350                fprintf(ausg,"%s\n",tmpstr);
351                free(tmpstr); tmpstr = NULL;
352
353                fprintf(ausg,"%s\n",node->day1);
354                fprintf(ausg,"%s\n",node->day1_low);
355                fprintf(ausg,"%s C\n",node->day1_high);
356                fprintf(ausg,"%s\n",node->day1_condition);
357                tmpstr = changeweatherpic(node->day1_icon);
358                fprintf(ausg,"%s\n",tmpstr);
359                free(tmpstr); tmpstr = NULL;
360               
361                fprintf(ausg,"%s\n",node->day2);
362                fprintf(ausg,"%s\n",node->day2_low);
363                fprintf(ausg,"%s C\n",node->day2_high);
364                fprintf(ausg,"%s\n",node->day2_condition);
365                tmpstr = changeweatherpic(node->day2_icon);
366                fprintf(ausg,"%s\n",tmpstr);
367                free(tmpstr); tmpstr = NULL;
368               
369                fprintf(ausg,"%s\n",node->day3);
370                fprintf(ausg,"%s\n",node->day3_low);
371                fprintf(ausg,"%s C\n",node->day3_high);
372                fprintf(ausg,"%s\n",node->day3_condition);
373                tmpstr = changeweatherpic(node->day3_icon);
374                fprintf(ausg,"%s\n",tmpstr);
375                free(tmpstr); tmpstr = NULL;
376               
377                fclose(ausg);
378                freeweather(node);
379                weatherthread = NULL;
380        }
381}
382               
Note: See TracBrowser for help on using the repository browser.