source: titan/plugins/lcdsamsung/lcd_weather.h @ 43368

Last change on this file since 43368 was 41585, checked in by gost, 6 years ago

[plugin] lcdsamsung fix and extensions

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