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

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

[titan] update download stuff step1

  • Property svn:executable set to *
File size: 12.5 KB
RevLine 
[16960]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
[17973]76        tmpsearch = ostrcat("data.aspx?weadegreetype=C&culture=de-DE&weasearchstr=", location, 0, 0);
[16960]77        //TODO: implement auto language (from titan.cfg)
[17973]78        //tmpsearch = ostrcat(tmpsearch, "&hl=de", 1, 0);
79//      tmpsearch = stringreplacechar(tmpsearch, ' ', '+');
[16960]80
[19884]81        tmpstr = gethttp("weather.service.msn.com", tmpsearch, 80, NULL, NULL, 5000, NULL, 0);
[16960]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
[17973]99                tmpstr2 = ostrstr(tmpstr1, "<weather weatherlocationcode=");
[16960]100                if(tmpstr2 != NULL)
101                {
102                        tmpstr1 = tmpstr2 + 5;
[17973]103                        weather->city = getxmlentry(tmpstr2, "weatherlocationname=");
[16960]104                }
105
[17973]106                tmpstr2 = ostrstr(tmpstr1, "<current ");
[16960]107                if(tmpstr2 != NULL)
108                {
109                        tmpstr1 = tmpstr2 + 5;
[17973]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=");
[16960]114                }
115               
[17973]116                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
[16960]117                if(tmpstr2 != NULL)
118                {
119                        tmpstr1 = tmpstr2 + 5;
[17973]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=");
[16960]125                }
126
[17973]127                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
[16960]128                if(tmpstr2 != NULL)
129                {
130                        tmpstr1 = tmpstr2 + 5;
[17973]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=");
[16960]136                }
137
[17973]138                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
[16960]139                if(tmpstr2 != NULL)
140                {
141                        tmpstr1 = tmpstr2 + 5;
[17973]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=");
[16960]147                }
148
[17973]149                tmpstr2 = ostrstr(tmpstr1, "<forecast ");
[16960]150                if(tmpstr2 != NULL)
151                {
152                        tmpstr1 = tmpstr2 + 5;
[17973]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=");
[16960]158                }
159
160                free(tmpstr); tmpstr = NULL;
161        }
162
163        return weather;
164}
165
166char* changeweatherpic(char* icon)
167{
[17973]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       
[16960]220        char* node = NULL;
221        if(icon == NULL)
222                return node;
[17973]223
224        else if(ostrstr(icon, "10") != NULL)
[18608]225                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/10.png", 0, 0);
[17973]226        else if(ostrstr(icon, "11") != NULL)
[18608]227                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/11.png", 0, 0);
[17973]228        else if(ostrstr(icon, "12") != NULL)
[18608]229                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/12.png", 0, 0);             
[17973]230        else if(ostrstr(icon, "13") != NULL)
[18608]231                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/13.png", 0, 0);     
[17973]232        else if(ostrstr(icon, "14") != NULL)
[18608]233                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/14.png", 0, 0);                     
[17973]234        else if(ostrstr(icon, "15") != NULL)
[18608]235                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/15.png", 0, 0);     
[17973]236        else if(ostrstr(icon, "16") != NULL)
[18608]237                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/16.png", 0, 0);     
[17973]238        else if(ostrstr(icon, "17") != NULL)
[18608]239                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/17.png", 0, 0);     
[17973]240        else if(ostrstr(icon, "18") != NULL)
[18608]241                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/18.png", 0, 0);     
[17973]242        else if(ostrstr(icon, "19") != NULL)
[18608]243                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/19.png", 0, 0);     
[17973]244        else if(ostrstr(icon, "20") != NULL)
[18608]245                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/20.png", 0, 0);     
[17973]246        else if(ostrstr(icon, "21") != NULL)
[18608]247                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/21.png", 0, 0);     
[17973]248        else if(ostrstr(icon, "22") != NULL)
[18608]249                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/22.png", 0, 0);     
[17973]250        else if(ostrstr(icon, "23") != NULL)
[18608]251                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/23.png", 0, 0);     
[17973]252        else if(ostrstr(icon, "24") != NULL)
[18608]253                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/24.png", 0, 0);     
[17973]254        else if(ostrstr(icon, "25") != NULL)
[18608]255                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/25.png", 0, 0);     
[17973]256        else if(ostrstr(icon, "26") != NULL)
[18608]257                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/26.png", 0, 0);     
[17973]258        else if(ostrstr(icon, "27") != NULL)
[18608]259                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/27.png", 0, 0);     
[17973]260        else if(ostrstr(icon, "28") != NULL)
[18608]261                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/28.png", 0, 0);
[17973]262        else if(ostrstr(icon, "29") != NULL)
[18608]263                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/29.png", 0, 0);     
[17973]264        else if(ostrstr(icon, "30") != NULL)
[18608]265                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/30.png", 0, 0);     
[17973]266        else if(ostrstr(icon, "31") != NULL)
[18608]267                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/31.png", 0, 0);     
[17973]268        else if(ostrstr(icon, "32") != NULL)
[18608]269                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/32.png", 0, 0);     
[17973]270        else if(ostrstr(icon, "33") != NULL)
[18608]271                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/33.png", 0, 0);     
[17973]272        else if(ostrstr(icon, "34") != NULL)
[18608]273                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/34.png", 0, 0);                     
[17973]274        else if(ostrstr(icon, "35") != NULL)
[18608]275                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/35.png", 0, 0);     
[17973]276        else if(ostrstr(icon, "36") != NULL)
[18608]277                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/36.png", 0, 0);     
[17973]278        else if(ostrstr(icon, "37") != NULL)
[18608]279                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/37.png", 0, 0);     
[17973]280        else if(ostrstr(icon, "38") != NULL)
[18608]281                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/38.png", 0, 0);     
[17973]282        else if(ostrstr(icon, "39") != NULL)
[18608]283                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/39.png", 0, 0);                     
[17973]284        else if(ostrstr(icon, "40") != NULL)
[18608]285                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/40.png", 0, 0);     
[17973]286        else if(ostrstr(icon, "41") != NULL)
[18608]287                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/41.png", 0, 0);     
[17973]288        else if(ostrstr(icon, "42") != NULL)
[18608]289                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/42.png", 0, 0);                     
[17973]290        else if(ostrstr(icon, "43") != NULL)
[18608]291                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/43.png", 0, 0);     
[17973]292        else if(ostrstr(icon, "44") != NULL)
[18608]293                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/44.png", 0, 0);     
[17973]294        else if(ostrstr(icon, "45") != NULL)
[18608]295                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/45.png", 0, 0);     
[17973]296        else if(ostrstr(icon, "46") != NULL)
[18608]297                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/46.png", 0, 0);     
[17973]298        else if(ostrstr(icon, "47") != NULL)
[18608]299                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/47.png", 0, 0);
[17973]300        else if(ostrstr(icon, "0") != NULL)
[18608]301                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/0.png", 0, 0);       
[17973]302        else if(ostrstr(icon, "1") != NULL)
[18608]303                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/1.png", 0, 0);       
[17973]304        else if(ostrstr(icon, "2") != NULL)
[18608]305                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/2.png", 0, 0);       
[17973]306        else if(ostrstr(icon, "3") != NULL)
[18608]307                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/3.png", 0, 0);
[17973]308        else if(ostrstr(icon, "4") != NULL)
[18608]309                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/4.png", 0, 0);       
[17973]310        else if(ostrstr(icon, "5") != NULL)
[18608]311                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/5.png", 0, 0);       
[17973]312        else if(ostrstr(icon, "6") != NULL)
[18608]313                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/6.png", 0, 0);       
[17973]314        else if(ostrstr(icon, "7") != NULL)
[18608]315                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/7.png", 0, 0);       
[17973]316        else if(ostrstr(icon, "8") != NULL)
[18608]317                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/8.png", 0, 0);
[17973]318        else if(ostrstr(icon, "9") != NULL)
[18608]319                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/9.png", 0, 0);               
320        else
[18676]321                node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/na.png", 0, 0);
322
323// fix warning
324        return node;
[16960]325}
326
327void lcd_writeweather()
328{
329       
330        char* tmpstr = NULL;
331        char* location = NULL;
332        struct weather* node = NULL;
333       
[17973]334        location = ostrcat(location, getconfig("lcd_pearl1_plugin_wetterort", NULL), 0, 0);
335        //location = ostrcat(location, getconfig("lcd_pearl1_plugin_wetterplz", NULL), 0, 0);
336        //location = ostrcat(location, "-", 1, 0);
337        //location = ostrcat(location, getconfig("lcd_pearl1_plugin_wetterland", NULL), 1, 0);
[16960]338
339        node = getweather(location);
340        free(location); location = NULL;
341
342        if(node != NULL)
343        {
344                FILE* ausg;
345                ausg=fopen("/tmp/lcdweather","w");
346
347                fprintf(ausg,"%s\n",node->date);
348                fprintf(ausg,"%s\n",node->day0);
349                fprintf(ausg,"%s\n",node->day0_low);
350                fprintf(ausg,"%s C\n",node->day0_high);
351                fprintf(ausg,"%s\n",node->day0_condition);
352                tmpstr = changeweatherpic(node->day0_icon);
353                fprintf(ausg,"%s\n",tmpstr);
354                free(tmpstr); tmpstr = NULL;
355
356                fprintf(ausg,"%s\n",node->day1);
357                fprintf(ausg,"%s\n",node->day1_low);
358                fprintf(ausg,"%s C\n",node->day1_high);
359                fprintf(ausg,"%s\n",node->day1_condition);
360                tmpstr = changeweatherpic(node->day1_icon);
361                fprintf(ausg,"%s\n",tmpstr);
362                free(tmpstr); tmpstr = NULL;
363               
364                fprintf(ausg,"%s\n",node->day2);
365                fprintf(ausg,"%s\n",node->day2_low);
366                fprintf(ausg,"%s C\n",node->day2_high);
367                fprintf(ausg,"%s\n",node->day2_condition);
368                tmpstr = changeweatherpic(node->day2_icon);
369                fprintf(ausg,"%s\n",tmpstr);
370                free(tmpstr); tmpstr = NULL;
371               
372                fprintf(ausg,"%s\n",node->day3);
373                fprintf(ausg,"%s\n",node->day3_low);
374                fprintf(ausg,"%s C\n",node->day3_high);
375                fprintf(ausg,"%s\n",node->day3_condition);
376                tmpstr = changeweatherpic(node->day3_icon);
377                fprintf(ausg,"%s\n",tmpstr);
378                free(tmpstr); tmpstr = NULL;
379               
380                fclose(ausg);
381                freeweather(node);
382        }
[19150]383        weatherthread = NULL;
[16960]384}
385               
Note: See TracBrowser for help on using the repository browser.