instPath = SystemPath( "ScriptPath" ) # turn everything OFF first KillScript("loop.mscr") RemoveNotifications(instPath&"\TitaniumWeather.exe") #RunOnPowerOn (instPath&"\TitaniumWeather.exe") # update interval set by user in minutes usertime = RegRead("HKLM","Software\TitaniumWeather","usertime")*60 forceupdate = RegRead("HKLM","Software\TitaniumWeather","forceupdate") # For manual updates (if usertime = 0, no scheduling is required) If (forceupdate && (usertime <> 0)) nextupdate = TimeStamp()+usertime RunAt(nextupdate, instPath&"\TitaniumWeather.exe") RegWriteDWord("HKLM","Software\TitaniumWeather","forceupdate",0) RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) # For auto updates ElseIf (usertime > 0) offtime = RegRead("HKLM", "Software\TitaniumWeather","OFFtime") ontime = RegRead("HKLM", "Software\TitaniumWeather","ONtime") # make sure ON/OFF times are valid hours If ( (offtime >= 0) AND (offtime <= 24) AND (ontime >= 0) AND (ontime <= 24) ) GetTime(currhour,currmin,currsec,currday,currmonth,curryear) # no wrap-around at midnight (hour 0) If (offtime > ontime) If (currhour >= ontime) If (currhour < offtime) # ON nextupdate = TimeStamp()+usertime RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) RunAt(nextupdate, instPath&"\TitaniumWeather.exe") Else # OFF - schedule for tomorrow RegWriteDWord("HKLM","Software\TitaniumWeather","fupdate",1) nextupdate = TimeStamp() + (ontime+24-currhour)*3600 - (currmin)*60 + Rand(300) RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) RunAt(nextupdate, instPath&"\TitaniumWeather.exe") #Run(instPath&"\loop.exe") exit EndIf Else # OFF - schedule for today RegWriteDWord("HKLM","Software\TitaniumWeather","fupdate",1) nextupdate = TimeStamp() + (ontime-currhour)*3600 - (currmin)*60 + Rand(300) RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) RunAt(nextupdate, instPath&"\TitaniumWeather.exe") #Run(instPath&"\loop.exe") exit EndIf # wrap-around midnight Else If ( (currhour < ontime) AND (currhour >= offtime) ) # OFF RegWriteDWord("HKLM","Software\TitaniumWeather","fupdate",1) nextupdate = TimeStamp() + (ontime-currhour)*3600 - (currmin)*60 + Rand(300) RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) RunAt(nextupdate, instPath&"\TitaniumWeather.exe") #Run(instPath&"\loop.exe") exit Else # ON nextupdate = TimeStamp()+usertime RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) RunAt(nextupdate, instPath&"\TitaniumWeather.exe") EndIf EndIf # invalid ON/OFF times or always update Else nextupdate = TimeStamp()+usertime RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) RunAt(nextupdate, instPath&"\TitaniumWeather.exe") EndIf EndIf # do not try to update if a call is active, try again in 5 min If (RegRead("HKLM","System\State\Phone","Status") AND 537067520) RemoveNotifications(instPath&"\TitaniumWeather.exe") nextupdate = TimeStamp()+300 RunAt(nextupdate, instPath&"\TitaniumWeather.exe") RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) exit EndIf ##################### If (RegValueExists("HKLM","Software\TitaniumWeather","fupdate")) fupdate = RegRead("HKLM", "Software\TitaniumWeather","fupdate") Else fupdate = 1 RegWriteDWord("HKLM","Software\TitaniumWeather","fupdate",fupdate) EndIf userauto = RegRead("HKLM", "Software\TitaniumWeather","userauto") location = RegRead("HKLM", "Software\TitaniumWeather","code") units = RegRead("HKLM", "Software\TitaniumWeather","units") startconn = RegRead("HKLM", "Software\TitaniumWeather","Connect") icontype = RegRead("HKLM", "Software\TitaniumWeather","Icons") If (RegValueExists("HKLM", "Services\myLocation","Latitude")) mylocation = 1 latitude = RegRead("HKLM", "Services\myLocation","Latitude") longitude = RegRead("HKLM", "Services\myLocation","Longitude") else mylocation = 0 EndIf If (usertime = 0) fupdate = 1 EndIf metric = 1 windunits = "mph" distunits = "miles" precipunits = "mm" #Update Panel RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","0") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","Time","Getting data via johnnyikon.com...") RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","1") If (startconn) connect("The Internet") Sleep 500 EndIf If(InternetConnected("http://google.com/m")) Call GetWeather # check if location is valid If (Find(weatherDataFromInternet[0], "Failed")) #Update Panel RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","Time","Failed to get weather.") RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","0") Exit EndIf #Update Panel RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","Time","Applying Update") RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","1") units = ToUpper(units) Call WriteToRegistry If (fupdate >= userauto) fupdate = 1 RegWriteDWord("HKLM","Software\TitaniumWeather","fupdate",fupdate) Else fupdate = fupdate + 1 RegWriteDWord("HKLM","Software\TitaniumWeather","fupdate",fupdate) EndIf #Update Panel RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","Time","Update Completed") RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","0") # if no internet, try again in 15 minutes Else RemoveNotifications(instPath&"\TitaniumWeather.exe") nextupdate = TimeStamp()+900 RunAt(nextupdate, instPath&"\TitaniumWeather.exe") RegWriteDWord("HKLM","Software\TitaniumWeather","nextupdate",nextupdate) #Update Panel RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","Time","No Internet?!") RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","0") Sleep(5000) oldtemp = RegRead("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","TodayTemps") oldtemp =substr(oldtemp, 1, 10) RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","CurrentIcon",instPath&"\"&icontype&"\na.png") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","CurrentTemp"," ") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\CondensedPage","PluginLabel",oldtemp) RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","1") wmsg=1 Return(wmsg) exit EndIf RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","Time","Forecast for "&w_city&" at "&w_date&".") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page9","TEXT2",w_city&", "&w_state) RegWriteDWord ("HKLM", "Software\Microsoft\CHome\TitaniumWeather","Updated","1") wmsg=1 Return(wmsg) Exit ####################################################################### Sub GetWeather link=ReadFile("http://www.johnnyikon.com/weather/w.php?lat="&latitude&"&lon="&longitude) w=Split(link, "|", TRUE); # Give nice names to make writing registry keys easier. w_lat = w[1] w_lon = w[2] w_woeid = w[3] w_country = w[4] w_state = w[5] w_city = w[6] w_street = w[7] # 8 is date woeid was resolved from lat and long # 9 is woeid again # 10 is date forecast expires w_date = w[11] w_windChill = w[12] w_windDirection = w[13] w_windSpeed = w[14] w_humid = w[15] w_vis = w[16] w_pres = w[17] # 18 is pressure fixed/falling/rising w_sunrise = w[19] w_sunset = w[20] w_condTxt = w[21] w_condId = w[22] w_tmp = w[23] w_high = w[24] w_low = w[25] w_lowTmrw = w[26] w_highTmrw = w[27] w_condTxtTmrw = w[28] w_condIdTmrw = w[29] EndSub ####################################################################### Sub WriteToRegistry RegWriteDWord("HKLM","Software\TitaniumWeather","forecastdays", 1) RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\CondensedPage","PluginLabel",w_tmp&"°C, "&w_condTxt) RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\CondensedPage","CurrentIcon",instPath&"\"&icontype&"\"&w_condId&".png") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","CurrentIcon",instPath&"\"&icontype&"\"&w_condId&".png") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","CurrentTemp",w_tmp&"°C") # write current detail page RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page2","CurrentIcon",instPath&"\"&icontype&"\"&w_condId&".png") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page2","CurrentTemp2",w_tmp&"°C") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page2","Day"," "&w_city&", "&w_state&" at "&w_date&".") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page2","Desc","Low: "&w_low&"°C. High: "&w_high&"°C.") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page2","Winds","Wind: "&w_windSpeed&windunits&" from "&w_windDirection&". "&" Chill: "&w_windChill&"°C") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page2","Prec","Humidity: "&w_humid&"%. Pressure: "&w_pres&"mb.") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page2","Other","Sunrise: "&w_sunrise&". Sunset: "&w_sunset&".") RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page1","TodayTemps",w_condTxt) RegWriteString ("HKLM", "Software\Microsoft\CHome\TitaniumWeather\Page2","TodayTemps",w_condTxt) For ct = 2 to 5 step 1 RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Day"&ct&"Icon",instPath&"\"&icontype&"\blank.png") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Day"&ct, "") Next # Delete useless extra pages #For ct = 3 to 7 step 1 # RegDeleteKey("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page"&ct, TRUE, TRUE) #Next # We use page 2 icon for today, and page 4 for tomorrow. RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Day2Icon",instPath&"\"&icontype&"\"&w_condId&".png") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Day2", "Today^CR^"&w_low&"° to "&w_high&"°") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Day4Icon",instPath&"\"&icontype&"\"&w_condIdTmrw&".png") RegWriteString("HKLM","Software\Microsoft\CHome\TitaniumWeather\Page1","Day4", "Tomorrow^CR^"&w_lowTmrw&"° to "&w_highTmrw&"°") #Write to S2U2 If (RegKeyExists("HKCU","Software\A_C\S2U2")) RegWriteString("HKCU","Software\A_C\S2U2","UserWeather","C|"&w_condId&"|"&w_tmp) EndIf EndSub