1 | |
---|
2 | struct stimerthread* weatherthread = NULL; |
---|
3 | |
---|
4 | struct 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 | |
---|
33 | void 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 | |
---|
70 | struct 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, 5000, 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 | |
---|
166 | char* 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%/lcdsamsung/skin/10.png", 0, 0); |
---|
226 | else if(ostrstr(icon, "11") != NULL) |
---|
227 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/11.png", 0, 0); |
---|
228 | else if(ostrstr(icon, "12") != NULL) |
---|
229 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/12.png", 0, 0); |
---|
230 | else if(ostrstr(icon, "13") != NULL) |
---|
231 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/13.png", 0, 0); |
---|
232 | else if(ostrstr(icon, "14") != NULL) |
---|
233 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/14.png", 0, 0); |
---|
234 | else if(ostrstr(icon, "15") != NULL) |
---|
235 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/15.png", 0, 0); |
---|
236 | else if(ostrstr(icon, "16") != NULL) |
---|
237 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/16.png", 0, 0); |
---|
238 | else if(ostrstr(icon, "17") != NULL) |
---|
239 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/17.png", 0, 0); |
---|
240 | else if(ostrstr(icon, "18") != NULL) |
---|
241 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/18.png", 0, 0); |
---|
242 | else if(ostrstr(icon, "19") != NULL) |
---|
243 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/19.png", 0, 0); |
---|
244 | else if(ostrstr(icon, "20") != NULL) |
---|
245 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/20.png", 0, 0); |
---|
246 | else if(ostrstr(icon, "21") != NULL) |
---|
247 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/21.png", 0, 0); |
---|
248 | else if(ostrstr(icon, "22") != NULL) |
---|
249 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/22.png", 0, 0); |
---|
250 | else if(ostrstr(icon, "23") != NULL) |
---|
251 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/23.png", 0, 0); |
---|
252 | else if(ostrstr(icon, "24") != NULL) |
---|
253 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/24.png", 0, 0); |
---|
254 | else if(ostrstr(icon, "25") != NULL) |
---|
255 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/25.png", 0, 0); |
---|
256 | else if(ostrstr(icon, "26") != NULL) |
---|
257 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/26.png", 0, 0); |
---|
258 | else if(ostrstr(icon, "27") != NULL) |
---|
259 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/27.png", 0, 0); |
---|
260 | else if(ostrstr(icon, "28") != NULL) |
---|
261 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/28.png", 0, 0); |
---|
262 | else if(ostrstr(icon, "29") != NULL) |
---|
263 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/29.png", 0, 0); |
---|
264 | else if(ostrstr(icon, "30") != NULL) |
---|
265 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/30.png", 0, 0); |
---|
266 | else if(ostrstr(icon, "31") != NULL) |
---|
267 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/31.png", 0, 0); |
---|
268 | else if(ostrstr(icon, "32") != NULL) |
---|
269 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/32.png", 0, 0); |
---|
270 | else if(ostrstr(icon, "33") != NULL) |
---|
271 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/33.png", 0, 0); |
---|
272 | else if(ostrstr(icon, "34") != NULL) |
---|
273 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/34.png", 0, 0); |
---|
274 | else if(ostrstr(icon, "35") != NULL) |
---|
275 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/35.png", 0, 0); |
---|
276 | else if(ostrstr(icon, "36") != NULL) |
---|
277 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/36.png", 0, 0); |
---|
278 | else if(ostrstr(icon, "37") != NULL) |
---|
279 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/37.png", 0, 0); |
---|
280 | else if(ostrstr(icon, "38") != NULL) |
---|
281 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/38.png", 0, 0); |
---|
282 | else if(ostrstr(icon, "39") != NULL) |
---|
283 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/39.png", 0, 0); |
---|
284 | else if(ostrstr(icon, "40") != NULL) |
---|
285 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/40.png", 0, 0); |
---|
286 | else if(ostrstr(icon, "41") != NULL) |
---|
287 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/41.png", 0, 0); |
---|
288 | else if(ostrstr(icon, "42") != NULL) |
---|
289 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/42.png", 0, 0); |
---|
290 | else if(ostrstr(icon, "43") != NULL) |
---|
291 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/43.png", 0, 0); |
---|
292 | else if(ostrstr(icon, "44") != NULL) |
---|
293 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/44.png", 0, 0); |
---|
294 | else if(ostrstr(icon, "45") != NULL) |
---|
295 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/45.png", 0, 0); |
---|
296 | else if(ostrstr(icon, "46") != NULL) |
---|
297 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/46.png", 0, 0); |
---|
298 | else if(ostrstr(icon, "47") != NULL) |
---|
299 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/47.png", 0, 0); |
---|
300 | else if(ostrstr(icon, "0") != NULL) |
---|
301 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/0.png", 0, 0); |
---|
302 | else if(ostrstr(icon, "1") != NULL) |
---|
303 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/1.png", 0, 0); |
---|
304 | else if(ostrstr(icon, "2") != NULL) |
---|
305 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/2.png", 0, 0); |
---|
306 | else if(ostrstr(icon, "3") != NULL) |
---|
307 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/3.png", 0, 0); |
---|
308 | else if(ostrstr(icon, "4") != NULL) |
---|
309 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/4.png", 0, 0); |
---|
310 | else if(ostrstr(icon, "5") != NULL) |
---|
311 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/5.png", 0, 0); |
---|
312 | else if(ostrstr(icon, "6") != NULL) |
---|
313 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/6.png", 0, 0); |
---|
314 | else if(ostrstr(icon, "7") != NULL) |
---|
315 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/7.png", 0, 0); |
---|
316 | else if(ostrstr(icon, "8") != NULL) |
---|
317 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/8.png", 0, 0); |
---|
318 | else if(ostrstr(icon, "9") != NULL) |
---|
319 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/9.png", 0, 0); |
---|
320 | else |
---|
321 | node = ostrcat(node, "%pluginpath%/lcdsamsung/skin/na.png", 0, 0); |
---|
322 | |
---|
323 | // fix warning |
---|
324 | return node; |
---|
325 | } |
---|
326 | |
---|
327 | void lcd_writeweather() |
---|
328 | { |
---|
329 | |
---|
330 | char* tmpstr = NULL; |
---|
331 | char* location = NULL; |
---|
332 | struct weather* node = NULL; |
---|
333 | |
---|
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); |
---|
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 | } |
---|
383 | weatherthread = NULL; |
---|
384 | } |
---|
385 | |
---|