1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
define_type(
'weatherbug',
-prototype,
-description='Interfaces with the WeatherBug Pipe Delimited API.'
);
local(
'key' = string,
'ZipCode' = integer,
'StationID' = string,
'Units' = 0,
't' = integer,
'required' = (: 'key', 'ZipCode', 'StationID', 'Units', 't'),
'baseurl' = '.isapi.wxbug.net/',
'methods' = map(
'getliveweather' = map(
'methodexe' = 'WxDataISAPI/WxDataISAPI.dll',
'getparams' = array(
'Magic' = 10991,
'RegNum' = 0,
'ZipCode' = null, // ZIP
'StationID' = null, // StationID
'Units' = integer, // 0 or 1
'Version' = 7,
'Fore' = 0,
't' = null // UID
),
'returnvalues' = array(
'Magic Number',
'Time',
'Date',
'Temperature',
'Wind direction',
'Wind Speed',
'Gust Wind Direction',
'Gust Wind Speed',
'Today Rainfall',
'Rainfall Rate',
'Barometer',
'Humidity',
'High Temp',
'Low Temp',
'Dew Point',
'Wind Chill',
'Monthly Rain',
'Temperature Rate',
'Humidity Rate',
'Barometer Rate',
'High Humidity',
'Low Humidity',
'High Barometer',
'Low Barometer',
'Max Rain Rate',
'Gust Time',
'Average Wind Direction',
'Average Wind Speed',
'Indoor Temp',
'Auxiliary Temp',
'Light',
'Yearly Rainfall',
'Indoor Temp Rate',
'Aux Temp Rate',
'Light Rate',
'Station Name',
'City and State Name',
'Active Query Frequency',
'Inactive/Background Query Frequency'
)
),
'gettwodayforecast' = map(
'methodexe' = 'forecastISAPI/ForecastISAPI.dll',
'getparams' = array(
'Magic' = 10992,
'RegNum' = 0,
'ZipCode' = null, // ZIP
'StationID' = null, // StationID
'Version' = 7,
'Units' = integer, // 0 or 1
't' = null // UID
),
'returnvalues' = array(
'Magic Number',
'ForeCastTitle1',
'High1',
'Low1',
'Condition1',
'ForeCastTitle2',
'High2',
'Low2',
'Condition2',
'Sunrise',
'Sunset',
'Query Frequency'
)
),
'getthreedayforecast' = map(
'methodexe' = 'forecastISAPI/ForecastISAPI.cgi',
'getparams' = array(
'GetForecast60',
'Magic' = 10992,
'RegNum' = 0,
'ZipCode' = null, // ZIP
'StationID' = null, // StationID
'Version' = 7,
'Units' = integer, // 0 or 1
't' = null, // UID
'lv' = 0
),
'returnvalues' = array(
'Magic Number',
'UpdateTime', // unix timestamp
'Today Title',
'Today High',
'Today Low',
'Today Condition #',
'Today Condition Text 1',
'Today Condition Text 2',
'Tomorrow Title',
'Tomorrow High',
'Tomorrow Low',
'Tomorrow Condition #',
'Tomorrow Condition Text 1',
'Tomorrow Condition Text 2',
'Third day Title',
'Third day High',
'Third day Low',
'Third day Condition #',
'Third day Condition Text 1',
'Third day Condition Text 2',
'SunRise', // unix timestamp
'SunSet', // unix timestamp
'Frequency'
)
),
'getstations' = map(
'methodexe' = 'wxdataisapi/wxdataisapi.dll',
'getparams' = array(
'getstations',
'ZipCode' = null, // ZIP
'magic' = 21771
),
'returnvalues' = array(
'Magic Number',
'NoofStations',
'ZipCode',
'StationID', // items from here down repeat for each station found
'Station Name',
'City, State',
'Distance from Zip Code center',
'Station_Type', // 0:Internet 1:Modem
'City, State of Given ZipCode'
)
),
'getalerts' = map(
'methodexe' = 'WxAlertISAPI/WxAlertIsapi.cgi',
'getparams' = array(
'GetAlert60',
'Magic' = 160,
'ZipCode' = null, // ZIP
'StationID' = null, // StationID
'Units' = integer, // 0 or 1
'RegNum' = 0,
'Version' = 7,
't' = null, // UID
'lv' = 0
),
'returnvalues' = array(
'Magic Number',
'Interval', // seconds
'Number of Alerts', // up to 10
'Alert ID', // items from here down repeat for each alert found
'Alert Type',
'Alert Expires' // unix timestamp (UTC)
)
)
),
'alerts' = map(
2 = 'Coastal Flood Warning',
3 = 'Flash Flood Warning',
21 = 'Flood Warning',
22 = 'Lakeshore Warning Statement',
23 = 'Marine Advisory / Warning',
24 = 'Special Marine Warning',
25 = 'Severe Thunderstorm Warning',
26 = 'Tornado Warning',
27 = 'Tsunami Watch / Warning',
28 = 'Coastal Flood Watch',
29 = 'Coastal Flood Statement',
30 = 'Flash Flood Watch',
31 = 'Flash Flood Statement',
32 = 'Flood Statement',
33 = 'Hurricane Local Statement',
34 = 'Marine Weather Statement',
35 = 'Severe Local Storm Watch',
36 = 'Severe Local Storm Watch Area Outline',
37 = 'Severe Weather Statement',
38 = 'Severe Local Storm Watch',
39 = 'Watch by County Outline',
40 = 'Severe Local Storm Watch',
81 = 'Winter Storm Warning',
101 = 'Non Precipitation Advisory',
102 = 'Storm Warning Outline',
103 = 'Dust Storm Warning',
121 = 'Earthquake Summary',
122 = 'Winter Storm Watch',
161 = 'High Surf Warning',
180 = 'Civil Emergency Message',
181 = 'Tornado Watch',
182 = 'Severe Thunderstorm Watch',
183 = 'Winter Weather Advisory',
201 = 'NBC StormCenter Update',
202 = 'NOW Forecast',
221 = 'Local Forecast',
241 = 'Fire Weather Message',
261 = 'Storm Information',
262 = 'Local Storm Report',
282 = 'Hurricane Forecast Advisory',
283 = 'Hurricane Public Advisory',
284 = 'Hurricane Discussion',
285 = 'Hurrican Probabilities',
286 = 'Tropical Storm Warning',
287 = 'Tropical Storm Watch',
300 = 'Administrative Message',
301 = 'Avalanche Watch',
302 = 'Avalanche Warning',
303 = 'Child Abduction Emergency',
304 = 'Civil Danger Warning',
305 = 'Earthquake Warning',
306 = 'Evacuation Immediate',
307 = 'Fire Warning',
308 = 'Hazardous Materials Warning',
309 = 'Law Enforcement Warning',
310 = 'Local Area Emergency',
311 = '911 Telephone Outage Emergency',
312 = 'Nuclear Power Plant Warning',
313 = 'Radiological Hazard Warning',
314 = 'Shelter In Place Warning',
315 = 'Volcano Warning',
400 = 'Tropical Rainfall Estimate',
401 = 'Tropical Position Estimate',
402 = 'Tropical Cyclone Update',
403 = 'Tropical Disturbance Statement',
404 = 'Tropical Weather Outlook',
405 = 'Monthly Tropical Weather Summary',
406 = 'Tropical Weather Discussion',
407 = 'Wind Speed Probabilities'
),
'conditions' = map(
0 = (: 'Day', 'Clear'),
1 = (: 'Day', 'Cloudy'),
2 = (: 'Night', 'Partly Cloudy'),
3 = (: 'Day', 'Partly Cloudy'),
4 = (: 'Day', 'Partly Sunny'),
5 = (: 'Day', 'Rain'),
6 = (: 'Day', 'Thunderstorms'),
7 = (: 'Day', 'Sunny'),
8 = (: 'Day', 'Snow'),
9 = (: 'Day', 'Flurries'),
10 = (: 'Either', 'Unknown'),
11 = (: 'Day', 'Chance of Snow'),
12 = (: 'Night', 'Snow'),
13 = (: 'Night', 'Cloudy'),
14 = (: 'Night', 'Rain'),
15 = (: 'Night', 'Chance of Rain'),
16 = (: 'Night', 'Partly Sunny'),
17 = (: 'Night', 'Sunny'),
18 = (: 'Night', 'Thunderstorms'),
19 = (: 'Day', 'Chance of Flurry'),
20 = (: 'Day', 'Chance of Rain'),
21 = (: 'Day', 'Chance of Sleet'),
22 = (: 'Day', 'Chance of Storms'),
23 = (: 'Day', 'Hazy'),
24 = (: 'Day', 'Mostly Cloudy'),
25 = (: 'Day', 'Sleet'),
26 = (: 'Day', 'Mostly Sunny'),
27 = (: 'Night', 'Chance of Flurry'),
28 = (: 'Night', 'Chance of Sleet'),
29 = (: 'Night', 'Chance of Snow'),
30 = (: 'Night', 'Chance of Storms'),
31 = (: 'Night', 'Clear'),
32 = (: 'Night', 'Flurries'),
33 = (: 'Night', 'Hazy'),
34 = (: 'Night', 'Mostly Cloudy'),
35 = (: 'Night', 'Mostly Sunny'),
36 = (: 'Night', 'Sleet'),
37 = (: 'Either', 'Unknown'),
38 = (: 'Day', 'Chance of Rain Showers'),
39 = (: 'Day', 'Chance of Snow Showers'),
40 = (: 'Day', 'Snow Showers'),
41 = (: 'Day', 'Rain Showers'),
42 = (: 'Night', 'Chance of Rain Showers'),
43 = (: 'Night', 'Chance of Snow Showers'),
44 = (: 'Night', 'Snow Showers'),
45 = (: 'Night', 'Rain Showers'),
46 = (: 'Day', 'Freezing Rain'),
47 = (: 'Night', 'Freezing Rain'),
48 = (: 'Day', 'Chance Freezing Rain'),
49 = (: 'Night', 'Chance Freezing Rain'),
50 = (: 'Day', 'Windy'),
51 = (: 'Day', 'Fog'),
52 = (: 'Day', 'Scattered Showers'),
53 = (: 'Day', 'Scattered Thunderstorms'),
54 = (: 'Day', 'Light Snow'),
55 = (: 'Day', 'Chance of Light Snow'),
56 = (: 'Day', 'Frozen Mix'),
57 = (: 'Day', 'Chance of Frozen Mix'),
58 = (: 'Day', 'Drizzle'),
59 = (: 'Day', 'Chance of Drizzle'),
60 = (: 'Day', 'Freezing Drizzle'),
61 = (: 'Day', 'Chance of Freezing Drizzle'),
62 = (: 'Day', 'Heavy Snow'),
63 = (: 'Day', 'Heavy Rain'),
64 = (: 'Day', 'Hot and Humid'),
65 = (: 'Day', 'Very Hot'),
66 = (: 'Day', 'Increasing Clouds'),
67 = (: 'Day', 'Clearing'),
68 = (: 'Day', 'Mostly Cloudy'),
69 = (: 'Day', 'Very Cold'),
70 = (: 'Night', 'Mostly Clear'),
71 = (: 'Night', 'Increasing Clouds'),
72 = (: 'Night', 'Clearing'),
73 = (: 'Night', 'Mostly Cloudy'),
74 = (: 'Night', 'Very Cold'),
75 = (: 'Night', 'Warm and Humid'),
76 = (: 'Either', 'now'),
77 = (: 'Either', 'exclamation'),
78 = (: 'Day', '30% Chance of Snow'),
79 = (: 'Day', '40% Chance of Snow'),
80 = (: 'Day', '50% Chance of Snow'),
81 = (: 'Day', '30% Chance of Rain'),
82 = (: 'Day', '40% Chance of Rain'),
83 = (: 'Day', '50% Chance of Rain'),
84 = (: 'Day', '30% Chance of Flurry'),
85 = (: 'Day', '40% Chance of Flurry'),
86 = (: 'Day', '50% Chance of Flurry'),
87 = (: 'Day', '30% Chance of Rain'),
88 = (: 'Day', '40% Chance of Rain'),
89 = (: 'Day', '50% Chance of Rain'),
90 = (: 'Day', '30% Chance of Sleet'),
91 = (: 'Day', '40% Chance of Sleet'),
92 = (: 'Day', '50% Chance of Sleet'),
93 = (: 'Day', '30% Chance of Storms'),
94 = (: 'Day', '40% Chance of Storms'),
95 = (: 'Day', '50% Chance of Storms'),
96 = (: 'Day', '30% Chance of Flurry'),
97 = (: 'Day', '40% Chance of Flurry'),
98 = (: 'Day', '50% Chance of Flurry'),
99 = (: 'Day', '30% Chance of Sleet'),
100 = (: 'Day', '40% Chance of Sleet'),
101 = (: 'Day', '50% Chance of Sleet'),
102 = (: 'Night', '30% Chance of Snow'),
103 = (: 'Night', '40% Chance of Snow'),
104 = (: 'Night', '50% Chance of Snow'),
105 = (: 'Night', '30% Chance of Storms'),
106 = (: 'Night', '40% Chance of Storms'),
107 = (: 'Night', '50% Chance of Storms'),
108 = (: 'Night', '30% Chance Rain Shower'),
109 = (: 'Night', '40% Chance Rain Shower'),
110 = (: 'Night', '50% Chance Rain Shower'),
111 = (: 'Night', '30% Chance Snow Shower'),
112 = (: 'Night', '40% Chance Snow Shower'),
113 = (: 'Night', '50% Chance Snow Shower'),
114 = (: 'Night', '30% Chance Rain Shower'),
115 = (: 'Night', '40% Chance Rain Shower'),
116 = (: 'Night', '50% Chance Rain Shower'),
117 = (: 'Night', '30% Chance Snow Shower'),
118 = (: 'Night', '40% Chance Snow Shower'),
119 = (: 'Night', '50% Chance Snow Shower'),
120 = (: 'Day', '30% Chance Freezing Rain'),
121 = (: 'Day', '40% Chance Freezing Rain'),
122 = (: 'Day', '50% Chance Freezing Rain'),
123 = (: 'Day', '30% Chance Freezing Rain'),
124 = (: 'Day', '40% Chance Freezing Rain'),
125 = (: 'Day', '50% Chance Freezing Rain'),
126 = (: 'Day', '30% Chance of Light Snow'),
127 = (: 'Day', '40% Chance of Light Snow'),
128 = (: 'Day', '50% Chance of Light Snow'),
129 = (: 'Day', '30% Chance of Frozen Mix'),
130 = (: 'Day', '40% Chance of Frozen Mix'),
131 = (: 'Day', '50% Chance of Frozen Mix'),
132 = (: 'Day', '30% Chance of Drizzle'),
133 = (: 'Day', '40% Chance of Drizzle'),
134 = (: 'Day', '50% Chance of Drizzle'),
135 = (: 'Day', '30% Chance Freezing Drizzle'),
136 = (: 'Day', '40% Chance Freezing Drizzle'),
137 = (: 'Day', '50% Chance Freezing Drizzle'),
138 = (: 'Day', 'Chance of Snow'),
139 = (: 'Night', 'Chance of Rain'),
140 = (: 'Day', 'Chance of Flurry'),
141 = (: 'Day', 'Chance of Rain'),
142 = (: 'Day', 'Chance of Sleet'),
143 = (: 'Day', 'Chance of Storms'),
144 = (: 'Night', 'Chance of Flurry'),
145 = (: 'Night', 'Chance of Sleet'),
146 = (: 'Night', 'Chance of Snow'),
147 = (: 'Night', 'Chance of Storms'),
148 = (: 'Day', 'Chance Rain Shower'),
149 = (: 'Day', 'Chance Snow Shower'),
150 = (: 'Night', 'Chance Rain Shower'),
151 = (: 'Night', 'Chance Snow Shower'),
152 = (: 'Day', 'Chance Freezing Rain'),
153 = (: 'Night', 'Chance Freezing Rain'),
154 = (: 'Day', 'Chance of Light Snow'),
155 = (: 'Day', 'Chance of Frozen Mix'),
156 = (: 'Day', 'Chance of Drizzle'),
157 = (: 'Day', 'Chance Freezing Drizzle')
)
);
define_tag('oncreate');
self->setparams(params);
/define_tag;
define_tag('setparams', -req='params', -copy);
self->t = lasso_uniqueid;
iterate(self->required, local('i'));
#params >> ('-' + #i) ? self->#i = #params->find('-' + #i)->first->second;
/iterate;
/define_tag;
define_tag('checkparams');
return(boolean(self->key && (self->ZipCode || self->stationID)));
/define_tag;
define_tag('getcondition', -req='num');
local('out') = self->conditions->find(#num);
return(#out);
/define_tag;
define_tag('getalert', -req='num');
local('out') = self->alerts->find(#num);
return(#out);
/define_tag;
define_tag('getdata', -req='methodname', -copy);
params->size > 1 ? self->setparams(params);
!self->checkparams ? return('Required parameters are missing.');
local('method') = @self->methods->find(#methodname);
local('methodexe') = @#method->find('methodexe');
local('url') = 'http://' + self->key + self->baseurl + #methodexe;
local('getparams') = #method->find('getparams');
local('returnvalues') = #method->find('returnvalues');
local('out') = map;
iterate(self->required, local('i'));
#getparams->find(#i)->size ? #getparams->find(#i)->first->second = self->#i;
/iterate;
// manually build query string because some params are not name/value pairs
local('querystring') = string;
iterate(#getparams, local('i'));
#querystring += (#i->isa('pair') ? #i->first + '=' + #i->second | #i) + '&';
/iterate;
#querystring->removetrailing('&');
#url += '?' + #querystring;
protect;
local('data') = include_url(
#url,
-timeout=10
)->exportstring('ISO-8859-1')->split('|');
#data->last == '' ? #data->removelast;
if( (: 'getliveweather', 'gettwodayforecast', 'getthreedayforecast') >> #methodname);
iterate(#returnvalues, local('i'));
#out->insert(#i = #data->get(loop_count));
/iterate;
else( (: 'getstations', 'getalerts') >> #methodname);
// separate first three return values from the rest
local('meta') = map;
iterate(#returnvalues, local('i'));
#meta->insert(#i = #data->get(loop_count));
loop_count == 3 ? loop_abort;
/iterate;
loop(3);
#data->removefirst;
#returnvalues->removefirst;
/loop;
local('itemdata' = map,);
local('results') = array;
iterate(#data, local('i'));
local('getme') = loop_count % #returnvalues->size;
#getme == 0 ? #getme = #returnvalues->size;
#itemdata->insert(#returnvalues->get(#getme) = #i);
if(#getme == #returnvalues->size);
#results->insert(#itemdata);
#itemdata = map;
/if;
/iterate;
#out = #meta;
#out->insert('Results' = #results);
/if;
return(#out);
handle_error;
local('err') = (#data->size ? #data | err_msg);
return(#err);
/handle_error;
/protect;
/define_tag;
define_tag('_unknowntag');
if(self->'methods'->keys >> tag_name);
local('out') = self->getdata(tag_name);
else(self->properties->first >> tag_name);
local('out') = @self->properties->first->find(tag_name);
else;
local('out') = null;
/if;
return(#out);
/define_tag;
/define_type;
|