// Copyright © 2008, Cranial Tap, Inc. // All rights reserved. // http://www.cranialtap.com/ // // Redistribution and use in source and binary forms, with or without // modification, are not permitted. // Globals string gZipCode; string gStationID; integer gUnitType; key gWeatherReqKey; // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 // time, station, city/state, curr temp, hi temp, lo temp, temp units, wind speed, wind units, wind dir, condition, today desc, tom desc list gWeatherData; // Constants string LICENSE_CODE = "A5448565444"; string LIVE_URL = "isapi.wxbug.net/WxDataISAPI/WxDataISAPI.dll?Magic=10991&RegNum=0&Version=7&Fore=0"; string THREE_DAY_URL = "isapi.wxbug.net/forecastISAPI/ForecastISAPI.cgi?GetForecast60&Magic=10992&RegNum=0&Version=7&lv=0"; integer REQUEST_WEATHER_DATA = 800850200; integer RETURN_WEATHER_DATA = 800850201; key wxbRequest(string base_url) { string req_url = "http://" + LICENSE_CODE + "." + base_url + "&ZipCode=" + llEscapeURL(gZipCode) + "&StationID=" + llEscapeURL(gStationID) + "&Units=" + (string)gUnitType + "&t=" + (string)llGetTime(); return llHTTPRequest(req_url, [ HTTP_MIMETYPE, "text/plain;charset=utf-8", HTTP_METHOD, "GET", HTTP_MIMETYPE, "application/x-www-form-urlencoded" ], ""); } default { state_entry() { gZipCode = ""; gStationID = ""; } http_response(key request_id, integer status, list metadata, string body) { if (request_id != gWeatherReqKey) return; if (llSubStringIndex(body, "10991|") == 0) { list body_list = llParseStringKeepNulls(body, ["|"], []); string temp_unit = "F"; string wind_unit = "MPH"; if (gUnitType == 1) { temp_unit = "C"; wind_unit = "KPH"; } string hi_temp = llList2String(body_list, 12); hi_temp = llGetSubString(hi_temp, 0, llStringLength(hi_temp) - 2); string lo_temp = llList2String(body_list, 13); lo_temp = llGetSubString(lo_temp, 0, llStringLength(lo_temp) - 2); gWeatherData = [ llList2String(body_list, 1), // time llList2String(body_list, 35), // station name llList2String(body_list, 36), // city, state llList2String(body_list, 3), // curr temp hi_temp, // hi temp lo_temp, // lo temp temp_unit, // temp units llList2String(body_list, 5), // wind speed wind_unit, // wind units llList2String(body_list, 4), // wind direction 999 ]; // temp condition num gWeatherReqKey = wxbRequest(THREE_DAY_URL); } else if (llSubStringIndex(body, "31|") == 0) { list l3DayForecast = llParseStringKeepNulls(body, ["|"], []); gWeatherData = llListReplaceList(gWeatherData, [llList2Integer(l3DayForecast, 5)], 10, 10); gWeatherData += llList2String(l3DayForecast, 6) + " " + llList2String(l3DayForecast, 7); string temp_unit = "F"; if (gUnitType == 1) temp_unit = "C"; gWeatherData += "High of " + llList2String(l3DayForecast, 9) + " " + temp_unit + ". " + llList2String(l3DayForecast, 12) + " " + llList2String(l3DayForecast, 13); llMessageLinked(LINK_THIS, RETURN_WEATHER_DATA, llDumpList2String(gWeatherData, "|"), NULL_KEY); gWeatherData = []; } } link_message(integer sender_num, integer num, string str, key id) { if (num == REQUEST_WEATHER_DATA) { list str_parts = llCSV2List(str); gZipCode = llList2String(str_parts, 0); gStationID = llList2String(str_parts, 1); gUnitType = llList2Integer(str_parts, 2); gWeatherReqKey = wxbRequest(LIVE_URL); } } } // Magic Numbers (first number in pipe delimited format) // 10991 - Live Weather Data // 10992 - 2 Day Forecast // 21771 - List of stations for zip code // 31 - 3 Day Forecast with conditions text // 160 - alerts // Live Weather // ----------------------------------------------------------------------------- // 0 - Magic Number (10991) 20 - High Humidity // 1 - Time 21 - Low Humidity // 2 - Date 22 - High Barometer // 3 - Temperature 23 - Low Barometer // 4 - Wind Direction 24 - Max Rain Rate // 5 - Wind Speed 25 - Gust Time // 6 - Gust Wind Direction 26 - Average Wind Direction // 7 - Gust Wind Speed 27 - Average Wind Speed // 8 - Today Rainfall 28 - Indoor Temp // 9 - Rainfall Rate 29 - Auxilliary Temp // 10 - Barometer 30 - Light // 11 - Humidity 31 - Yearly Rainfall // 12 - High Temp 32 - Indoor Temp Rate // 13 - Low Temp 33 - Aux Temp Rate // 14 - Dew Point 34 - Light Rate // 15 - Wind Chill 35 - Station Name // 16 - Monthly Rain 36 - City and State Name // 17 - Temperature Rate 37 - Active Query Frequency // 18 - Humidity Rate 38 - Inactive/Background Query Frequency // 19 - Barometer Rate // 3 Day Forecast // ----------------------------------------------------------------------------- // 0 - Magic Number (31) 12 - Tomorrow Condition Text 1 // 1 - Update Time (int secs from 1970) 13 - Tomorrow Condition Text 2 // 2 - Today Title 14 - Third Day Title // 3 - Today High 15 - Third Day High // 4 - Today Low 16 - Third Day Low // 5 - Today Condition # 17 - Third Day Condition # // 6 - Today Condition Text 1 18 - Third Day Condition Text 1 // 7 - Today Condition Text 2 19 - Third Day Condition Text 2 // 8 - Tomorrow Title 20 - SunRise (int secs from 1970) // 9 - Tomorrow High 21 - SunSet (int secs from 1970) // 10 - Tomorrow Low 22 - Frequency // 11 - Tomorrow Condition #