Zabaware Support Forums

Hal 6 and weather

Started by caangel43, February 11, 2007, 09:44:16 PM

Previous topic - Next topic

caangel43

#15
I wanted to thank you Bill I like the plugin alot would love to see it in the new hal update you did a great job thanks caangel

Bill DeWitt

quote:
Originally posted by caangel43

I wanted to thank you Bill I like the plugin alot would love to see it in the new hal update you did a great job thanks caangel


You're welcome.

I was happy to make it, not least because I had been wanting something like it myself. I work better with a little encouragement though.

I have almost gotten it to read a forecast, at least my VBS script will read a forecast string... I still have to import it to the original plugin in such a way that you can ask for a "weather forecast" and get that rather than just the "current weather".

That's just verbal scripting though, the hard part is mostly done.

My big fear is that as soon as I get it just the way I want it, those RSS providers will change to ATOM feeds or something and make me rewrite the whole thing...


caangel43

your doing a great job I look forward to more from you :-) caangel

Bill DeWitt

#18
I have posted a new update (same link as above), with weather forecast. As it is, you have to ask for either the current weather or the weather forecast. Reading the first part of the script will show you the range of questions you can ask, and they can be changed in the same way.

You will have to edit the RSS feed address to reflect your own area. This line:

       objXMLNews.load("http://www.intellicast.com/IcastRSS/FcstRSS.aspx?loc=XXXXX&CID=15786")

Would have "XXXXX" changed to your zipcode. That should work, but if not, go to the Intellicast site and find your personal forcast feed and try that.

If that doesn't work, post your zip code and I will try to edit a copy so that it will work.

I really enjoy having a weather forecast and current weather read to me on request. I am glad that this was asked for so I had an excuse to really work on it.

PS: I do know the correct spelling of "fahrenheit" but spelling it wrong makes it pronounced right.


onthecuttingedge2005

#19
quote:
Originally posted by Bill DeWitt

I have posted a new update (same link as above), with weather forecast. As it is, you have to ask for either the current weather or the weather forecast. Reading the first part of the script will show you the range of questions you can ask, and they can be changed in the same way.

You will have to edit the RSS feed address to reflect your own area. This line:

       objXMLNews.load("http://www.intellicast.com/IcastRSS/FcstRSS.aspx?loc=XXXXX&CID=15786")

Would have "XXXXX" changed to your zipcode. That should work, but if not, go to the Intellicast site and find your personal forcast feed and try that.

If that doesn't work, post your zip code and I will try to edit a copy so that it will work.

I really enjoy having a weather forecast and current weather read to me on request. I am glad that this was asked for so I had an excuse to really work on it.

PS: I do know the correct spelling of "fahrenheit" but spelling it wrong makes it pronounced right.




Hi Bill.

I hope you don't mind but I tweaked out your code a bit so that all the user has to do is say: My zip code is 12345 and HAL will store this for the weather forcast for future use.


Rem Type=Plugin
Rem Name= Weather Alert 3
Rem Author= Bill DeWitt, OnTheCuttingEdge2005
Rem Host=All

'-----------------------------------------------------------------
'This sub sets up the plug-ins option panel in Hal's options dialog
'-----------------------------------------------------------------

Sub OptionsPanel()
lblPlugin(0).Caption = "Simple plugin to read the weather conditions to you. Use different phrases for different reports - see script."
lblPlugin(0).Move 120, 120, 3300, 1200
lblPlugin(0).WordWrap = True
lblPlugin(0).Visible = True
End Sub


Rem PLUGIN: PLUGINAREA7

If HalBrain.CheckTableExistence("UserWeather") = False Then HalBrain.CreateTable "UserWeather", "TopicSearch", ""
GetWeatherPat = HalBrain.SearchPattern(UserSentence, "*ZIP CODE IS *", 2)
If GetWeatherPat <> "" Then
GetResponse = "I have stored your Zip code for future weather forecasts, from now on all you have to do is ask about your weather."
HalBrain.AddToTable "UserWeather", "TopicSearch", UserName, GetWeatherPat
End If


HalBrain.ReadOnlyMode = False
'Determines that you are talking about the weather
GetW = HalBrain.TopicSearch(UserName, "UserWeather")
If InStr(1,OriginalSentence, "weather",1) And Len(GetW) > 2 Then
GetResponse = GetForecast(UserName)
ElseIf InStr(1,OriginalSentence, "weather",1) And Len(GetW) < 2 Then
GetResponse = "I have not recorded your zip code for weather in your area, simply say, My zip code is 12345, where 12345 would be your zip code and I will save it for future weather look up in your area, after doing so simply say: Weather."
End If

Rem PLUGIN: FUNCTIONS

Function GetForecast(UserName)
       Dim objXMLNews
       Dim NewsArray()
       set objXMLNews = CreateObject("Msxml2.DomDocument.4.0")
       objXMLNews.async = False
       objXMLNews.ValidateOnParse = false
       GetW = HalBrain.TopicSearch(UserName, "UserWeather")
       objXMLNews.load("http://www.intellicast.com/IcastRSS/FcstRSS.aspx?loc=" & GetW & "&CID=15786")
       Dim xmlNodeNews
       set xmlNodeNews = objXMLNews.documentElement.selectNodes("//item")
       Dim xmlNewsItem
       dim strResult
       For Each xmlNewsItem In xmlNodeNews
           CountNews = CountNews+1
       Next
       ReDim NewsArray(CountNews-1)
       For Each xmlNewsItem In xmlNodeNews
           If xmlNewsItem.selectSingleNode("title").Text = "Forecast" Then
           Set oForcast = xmlNewsItem.selectSingleNode("description")
           End If
           If xmlNewsItem.selectSingleNode("title").Text = "High Temperature" Then
           Set oHighTemp = xmlNewsItem.selectSingleNode("description")
           End If
           If xmlNewsItem.selectSingleNode("title").Text = "Low Temperature" Then
           Set oLowTemp = xmlNewsItem.selectSingleNode("description")
           End If
       Next

s= DialogChooseThree("We are expecting ", "The forecast calls for ", "I'm told we will have ") & oForcast.text _
& DialogChooseThree(" weather with a high of ", " weather. Our high could reach ", " weather. The high temp should be ") & oHighTemp.text _
& DialogChooseThree(" and a low of ", " and our low may reach ", " and it may get as low as ") & oLowTemp.text & " degrees."
GetForecast = s
End Function

Function GetCurrent()

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("http://www.weather.gov/data/current_obs/KVSF.xml")

Set oWeather = objXMLDoc.documentElement.selectSingleNode("weather")
Set oTemperature = objXMLDoc.documentElement.selectSingleNode("temp_f")
Set oHumidity = objXMLDoc.documentElement.selectSingleNode("relative_humidity")
Set oWind = objXMLDoc.documentElement.selectSingleNode("wind_string")

s= DialogChooseThree("The weather is ", "The current conditions are ", "The weather at the airport is ") & oWeather.text _
& DialogChooseThree(". The present temperature is ", ". The temperature is ", ". It's ") & oTemperature.text & " degrees farenhite" _
& DialogChooseThree(", the relative humidity is ", ", the humidity outside is ", ", our humidity is at ") & oHumidity.text & " percent" _
& DialogChooseThree(" and the wind is ", " and winds are ", " and our winds are ") & oWind.text & "."

GetCurrent = s
End Function

Function DialogChooseThree(ChoiceOne, ChoiceTwo, ChoiceThree)
'--------------------------------------------
'Selects from three strings sent as arguments
'--------------------------------------------
Randomize
Select Case Int(rnd()*3)
Case 0 DialogChooseThree=ChoiceOne
Case 1 DialogChooseThree=ChoiceTwo
Case 2 DialogChooseThree=ChoiceThree
Case Else ChoiceOne
End Select
End Function


This also works with AIM bot.
Jerry[8D]

Bill DeWitt

quote:
Originally posted by onthecuttingedge2005
[
Hi Bill.

I hope you don't mind but I tweaked out your code a bit so that all the user has to do is say: My zip code is 12345 and HAL will store this for the weather forcast for future use.



No, I don't mind at all! That's a great improvement. I was working on a text box on the plugin option page, but this is probably better.

However, I noticed that you removed the current weather and the variety of phrases portions. Is that because they caused a problem, or can I safely put them back in?

Either way, thanks for your input! I truely believe that by fostering a wide vareity of plugins (and a wide variety of people making either plugins or suggestions for plugins), Hal can become an extremely useful AI.


caangel43

looks like this plugin is taking off thanks to both Bill's thanks for all your hard work caangel

caangel43

#22
Hi I put in the new plug it asked for my zip code so I gave it to hal but when I asked for the weather it would crash any help please I attached a picture of the error

caangel

Bill DeWitt

#23
quote:
Originally posted by caangel43

Hi I put in the new plug it asked for my zip code so I gave it to hal but when I asked for the weather it would crash


Your image didn't come through, but I can see one possible reason
why it doesn't work. Jerry's version doesn't have a function which is
called for in the script. He must already have the function, "DialogChooseThree()"
since it is used in some of my other plugins. Either that, or he posted a truncated version
which only contains the relevant changes.

(BTW, this points out a unnecessary redundancy in my programming
methods. Since many of my plugins could use common but purpose made
functions, Hal will append many copies of the same function into it's
script. I just checked and I have five copies!)

Either way, for now, it would be best to restore
your previous version of the plugin, and let some
more testing and changes go forward. I haven't even
had a chance to test it myself (...busy life). I suspect
that before too long, a version will be posted which
resolves this problem, and restores the other functions.

Let me know if you have problems restoring it.


caangel43

ok I set it back to number 2 I cant get the forcast to work can I send you the uhp to look at to see if I did thing right the reg weather check works fine thanks caangel

onthecuttingedge2005

#25
quote:
Originally posted by caangel43

Hi I put in the new plug it asked for my zip code so I gave it to hal but when I asked for the weather it would crash any help please I attached a picture of the error

caangel



Hi Caangel.

I have placed the whole code for you so you wont get the error, I only posted part of the code that I had changed to show bill some improvements, I posted it so bill could update his script with new triggers, sorry about the delay in posting the entire script.

Should work for you now.
Just copy and paste and save as MyWeather.uhp or if Bill updates his script just download his.

If I spot something else to improve upon it I will give notice here in these postings for Bill.
Jerry[8D]

caangel43

Hi I put in the new code but it will not show up in the plugin area as myweather caangel

caangel43

Hi I had to call it weather alert to make it work calling it myweather it would not show up as a plugin when you ask for the weather it gives you the forcaste now thanks caangel