Zabaware Support Forums

Zabaware Forums => Ultra Hal 7.0 => Topic started by: caangel43 on February 11, 2007, 09:44:16 pm

Title: Hal 6 and weather
Post by: caangel43 on February 11, 2007, 09:44:16 pm
Hi all I was wondering if a plugin could be made where hal will tell you the weather not just open a web page maybe make it that it will check the weather every 60 min or something like that thanks caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 11, 2007, 10:55:22 pm
"The weather" is a pretty wide subject, but yes, a plugin can be made to read many sorts of information off the web and then have Hal read them to you. I made a basic RSS header plugin, that reads just the headlines and you can ask Hal for a random one. I suspect that weather pages have RSS feeds of various sorts that you could tap into.

I'll think about it tomorrow. Maybe check boxes so you can decide what parts of "the weather" you mainly want to know.
Title: Hal 6 and weather
Post by: caangel43 on February 11, 2007, 11:10:05 pm
cool thank you caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 12, 2007, 09:02:02 pm
quote:
Originally posted by Bill DeWitt
I'll think about it tomorrow.


I found some weather feeds, but the one I like is actually an xml feed and my rss plugin doesn't work on it as I would like. I have to learn how to parse xml items first, but when I do I have it ready to read you the various local current observations and the forcast. May be a couple of days, because my mind is inherently incapable of absorbing new information.

BTW, here is the feed

<http://www.weather.gov/data/current_obs/>
Title: Hal 6 and weather
Post by: caangel43 on February 12, 2007, 09:48:06 pm
thank you for what your doing I am sure it will be very cool caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 12, 2007, 10:58:51 pm
For now you will have to do some editing yourself, to input the actual feed you really want. The one there gives weather in Vermont. Go to the feed I posted earlier, find your prefered location and subsitute the url for the one I used. The important part is the last part "XXXX.xml", you should find a four letter station id which is the weather station near your location. Mine is KVSF. Change that part to your station id and it should work.

Let me know if you have any problems, and keep an eye out for improvements in the next few days. Forcasts may require learning how to use the NDFD XML Simple Object Access Protocol (SOAP) server. Might take a while....

Weather Alert 2 ("http://ultrahalscript.pbwiki.com/Plugins%20under%20construction")
Title: Hal 6 and weather
Post by: caangel43 on February 12, 2007, 11:38:18 pm
not to sure what I am doing here after the page is edited what do you save it as and where do you put it am very bad at all this caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 12, 2007, 11:47:56 pm
Sorry, I thought you knew... my mistake.

Copy the code into a text editor, change the url, then save it as "WeatherAlert.uhp" in your UltraHal directory. Then restart Hal. You should then be able to find the plugin in the "General Options > Brain" dialog. Look for and put a check mark in "WeatherAlert 2".

Then to ask for the weather, say something like, "What does the National Weather Service say?" being sure to include the phrase "National Weather Service".

Later, I will make a sentence parsing function for it, to allow you to say different things and get the same result.
Title: Hal 6 and weather
Post by: caangel43 on February 13, 2007, 12:01:02 am
thank you I cant beleave I did it right it is working it opens the webpage and then reads it to you thanks for your help caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 13, 2007, 06:45:07 am
Good.

The page being opened must be from another weather plugin or something. Mine should just read the NWS information.
Title: Hal 6 and weather
Post by: caangel43 on February 13, 2007, 01:38:44 pm
I unchecked the other plugin and then hal just read the weather a very cool plugin thank you caangel
Title: Hal 6 and weather
Post by: caangel43 on February 16, 2007, 02:56:30 pm
Bill any news on a update on weather I was thinking can you made it that you ask how the weather is and hal reads to you if that can be done thanks Caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 16, 2007, 07:31:42 pm
There is progress, but I got distracted into making it keep a record and display a graph of past weather conditions. That works fairly well, if you have Excel on your machine.

I can take some time to fix the input parsing so that you can make a more general question work, that's pretty easy. Maybe tomorrow...
Title: Hal 6 and weather
Post by: caangel43 on February 16, 2007, 07:45:04 pm
I dont have that program but thank you for your help I like the plugin alot caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 16, 2007, 10:44:14 pm
I posted a slight update at the link above which allows you to ask for the weather in a wider variety of sentences.

Copy this over the old version and save it, then uncheck the weather plugin, click OK, go back into options and recheck the weather plugin. This resets Hal to include the new version. Then you should be able to use it.

If you look at it, you can see the range of phrases it checks for. You can add or change them as you see fit, as long as you leave the first two and the last line of the new section as they are. For instance, if you wanted to be able to just say "weather report" and get the response, you could simply add this line in the middle of the group:

   InStr(1,OriginalSentence, "report",1) Or _

This would make Hal check each sentence for "weather" then any sentence with "weather" would also be checked for "report". If both criteria are met, Hal will respond with the weather report.


Let me know if you have any problems.
Title: Hal 6 and weather
Post by: caangel43 on February 16, 2007, 11:11:06 pm
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
Title: Hal 6 and weather
Post by: Bill DeWitt on February 22, 2007, 11:38:37 pm
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...
Title: Hal 6 and weather
Post by: caangel43 on February 23, 2007, 01:17:48 am
your doing a great job I look forward to more from you :-) caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 23, 2007, 04:51:32 pm
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.
Title: Hal 6 and weather
Post by: onthecuttingedge2005 on February 25, 2007, 11:25:30 am
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.

Code: [Select]
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]
Title: Hal 6 and weather
Post by: Bill DeWitt on February 25, 2007, 12:59:02 pm
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.
Title: Hal 6 and weather
Post by: caangel43 on February 25, 2007, 03:26:11 pm
looks like this plugin is taking off thanks to both Bill's thanks for all your hard work caangel
Title: Hal 6 and weather
Post by: caangel43 on February 25, 2007, 03:35:58 pm
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

(http://www.zabaware.com/forum/uploaded/caangel43/2007225162140_Image2.jpg"]Image2.jpg)caangel
Title: Hal 6 and weather
Post by: Bill DeWitt on February 25, 2007, 04:58:53 pm
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.
Title: Hal 6 and weather
Post by: caangel43 on February 25, 2007, 05:34:48 pm
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
Title: Hal 6 and weather
Post by: onthecuttingedge2005 on February 25, 2007, 05:36:41 pm
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

(http://www.zabaware.com/forum/uploaded/caangel43/2007225162140_Image2.jpg"]Image2.jpg)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]
Title: Hal 6 and weather
Post by: caangel43 on February 25, 2007, 06:10:33 pm
Hi I put in the new code but it will not show up in the plugin area as myweather caangel
Title: Hal 6 and weather
Post by: caangel43 on February 25, 2007, 06:20:06 pm
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