dupa

Author Topic: Weather  (Read 8021 times)

dcole87

  • Newbie
  • *
  • Posts: 3
    • View Profile
Weather
« on: March 10, 2010, 03:41:37 pm »
Newbie here. Hi all!
I know that there is a plugin that allows Ultra Hal to take you to specific websites to view the weather, but is there any way to allow it to interpret the weather itself and read it back to you?

EX.
User: How's the weather today?
Hal: It's currently <TEMP>. Forecast for today is a high of <HighTemp> with <weather conditions>. Tonight, we'll see a low of <LowTemp> with <night conditions>.

What would the code for that look like?
 

onthecuttingedge2005

  • Guest
Weather
« Reply #1 on: March 10, 2010, 05:52:41 pm »
here you go.

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



Jerry[8D]

dcole87

  • Newbie
  • *
  • Posts: 3
    • View Profile
Weather
« Reply #2 on: March 10, 2010, 07:19:50 pm »
Thanks OTC! I'll let you know if there's a bug or two!
I really have no experience in programming at all - I'm one of THOSE Hal users - but I would like to learn! Expect to see me a bit more around the forums!
 

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Weather
« Reply #3 on: March 10, 2010, 07:39:06 pm »
I like this idea a lot
I tried this out, and I get this repeatedly.

Hal: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.
user: My zip code 02838
Hal: I have stored your Zip code for future weather forecasts, from now on all you have to do is ask about your weather.
user: how is the weather
Hal: 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.

This is on my windows 64 bit system.
I will try on my xp 32 bit system tomorrow.

onthecuttingedge2005

  • Guest
Weather
« Reply #4 on: March 10, 2010, 08:40:41 pm »
quote:
Originally posted by sybershot

I like this idea a lot
I tried this out, and I get this repeatedly.

Hal: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.
user: My zip code 02838
Hal: I have stored your Zip code for future weather forecasts, from now on all you have to do is ask about your weather.
user: how is the weather
Hal: 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.

This is on my windows 64 bit system.
I will try on my xp 32 bit system tomorrow.



when you go to the brain editor do you see a table called UserName Weather where UserName is what HAL calls you, this should contain your zipcode, it should only ask once if it was recorded, if it wasn't recorded then it might repeat if asked about the weather again.

try saying: My zip code is 02838, exactly, see if that helps. I might not of got all the possible statement triggers coded. but it sounds more like your zip code wasn't recorded for some reason.

I believe it didn't record your zip code because the word "IS" was not included in your statement of: My zip code 02838, there is no "IS", so the proper way: My Zip Code IS 12345.

Jerry

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Weather
« Reply #5 on: March 10, 2010, 10:33:45 pm »
I tried using is and it is a no go. I did before as well, just not the last time when I copied the sentence.

Table list is as followed

Script Editor
test/debug script
 - Tables
   + autolearningBrain
   + basicResponcess
   + mainBrain
   + miscData

I searched inside the four tables and nothing, is there a way to manually add it, to see if that would work?

dcole87

  • Newbie
  • *
  • Posts: 3
    • View Profile
Weather
« Reply #6 on: March 10, 2010, 10:59:07 pm »
If you have a program to open up UHF, you might.

Personally I was having issues with the bottom half of the script (GetCurrent Function). It doesn't bring up the current conditions at all.
 

onthecuttingedge2005

  • Guest
Weather
« Reply #7 on: March 10, 2010, 11:18:49 pm »
quote:
Originally posted by sybershot

I tried using is and it is a no go. I did before as well, just not the last time when I copied the sentence.

Table list is as followed

Script Editor
test/debug script
 - Tables
   + autolearningBrain
   + basicResponcess
   + mainBrain
   + miscData

I searched inside the four tables and nothing, is there a way to manually add it, to see if that would work?




If you create a table called:

test/debug script
 - Tables
   + UserNameWeather
   + autolearningBrain
   + basicResponcess
   + mainBrain
   + miscData

the script should find the table. where UserName is what HAL calls you. it is a topicsearch table and in it only contains your HAL username in the table search section and your zip code in the topic section.

example only, brackets are for display only, if you open the created table you will see 'Search' and 'Topic'
[Search: Master][Topic: 12345]

I really don't understand why you are having all the problems you have had, this script code has been on this site for quite some time and I don't think anybody had a problem with it till now.

I am very serious, it works great on my system as well, just plain weird.

the only thing I can think of is that somehow the table is not being appended to your system for some reason.

also, just copy and paste the code I gave and save it as WeatherAlert3.uhp under 'all' files in the Ultra Hal Assistant 6 folder.

lets see where it goes.
« Last Edit: March 10, 2010, 11:24:02 pm by onthecuttingedge2005 »

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Weather
« Reply #8 on: March 12, 2010, 08:34:04 pm »

quote:
also, just copy and paste the code I gave and save it as WeatherAlert3.uhp under 'all' files in the Ultra Hal Assistant 6 folder.

This is how I made the plug-in, I did not insert it directly into the brain, For I would not know where to put it.

I'm starting to realize just how crappy windows vista 64 bit is. If my system was not under warranty I would change my os a heart beat. I had a problem like this with a the gretta log plug-in, where it would not create a folder. I manually created the Log folder needed, changed a path location and it worked fine.

I created a topic search table
test/debug script
- Tables
+ MasterWeather (the icon is six small folder looking icons with a -)
+ autolearningBrain
+ basicResponcess
+ mainBrain
+ miscData

I double clicked to open edit mode inserted input now shows this
______________________________________________________________
   | Search                 | Topic                          
______________________________________________________________
   | Master                 |                           02838
______________________________________________________________

I shut down brain editor, and re opened brain editor to check if info saved. It did[:D]. I started the Ultra Hal program for I had it totally shut down, It still said "it has not recorded a zip code", when asked about weather. So I wrote "My zip code is 02838" hit enter, and it says "it is stored". When asked about weather again I get "your zip code is not stored" still[:(]


onthecuttingedge2005

  • Guest
Weather
« Reply #9 on: March 13, 2010, 12:12:28 pm »
make a topicsearch table called: "UserWeather" exactly then place under search: Master then under topic put in your zipcode: 02838.

see if that works. don't use the MasterWeather table, for some reason hal only see the UserWeather as the main users table but inside you place what hal calls you and your zip.

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Weather
« Reply #10 on: March 13, 2010, 06:47:05 pm »
Thanks for all your time and help with this, It's greatly appreciated. I renamed MasterWeather to UserWeather This did not work, I get the same results. I deleted the table and created a new table/topic search using UserWeather as the name, and still same results.


onthecuttingedge2005

  • Guest
Weather
« Reply #11 on: March 14, 2010, 11:55:37 am »
Hi Sybershot.

I updated the plugin, you can manually put your zip code in both code sections to manually override zip code tables.

I have modded the plugin to work with your zip code manually, try this plugin and let me know if it works with your HAL.





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")

'Added Mod here
If Len(GetW) < 2 Then GetW = "02838" '<--- You can add your zip code manually here if you wish.

If InStr(1,OriginalSentence, "weather",1) And Len(GetW) > 2 Then
GetResponse = "For the " & GetW & " zipcode area, " & 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")
       
        'Added Mod here
        If Len(GetW) < 2 Then GetW = "02838" '<--- You can add your zip code manually here if you wish.
       
        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




I hope it works.

Jerry
« Last Edit: March 14, 2010, 07:45:32 pm by onthecuttingedge2005 »

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Weather
« Reply #12 on: March 14, 2010, 04:34:59 pm »
User: My zip code is 02838
Hal: Certainly

User: what is the  weather
HalScript Error on line 4331 in column 8: ActiveX component can't
create object:'Msxmli2.DomDocument.4.0'

User: todays weather
HalScript Error 429 on line 4331 in coumn 8: ActiveX component can't
create object:'Msxmli2.DomDocument.4.0'

onthecuttingedge2005

  • Guest
Weather
« Reply #13 on: March 14, 2010, 07:41:04 pm »
quote:
Originally posted by sybershot

User: My zip code is 02838
Hal: Certainly

User: what is the  weather
HalScript Error on line 4331 in column 8: ActiveX component can't
create object:'Msxmli2.DomDocument.4.0'

User: todays weather
HalScript Error 429 on line 4331 in coumn 8: ActiveX component can't
create object:'Msxmli2.DomDocument.4.0'




Hi Sybershot.

check your registry, go to run, type in regedit, go to:

HKEY_CLASSES_ROOT\Msxml2.DOMDocument.4.0

if it doesn't exist in your registry you will have to
try downloading MSXML 4.0 from Microsoft and installing it, should be download MSXML 4.0 service pack 2 I believe.


I also updated the weather alert 3 plugin, there are two place you will have to put your zip code in to manually override zipcode tables.
« Last Edit: March 14, 2010, 07:49:07 pm by onthecuttingedge2005 »

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Weather
« Reply #14 on: March 14, 2010, 08:06:13 pm »
That worked perfectly. you are a problem solving, coding God. Thanks a million, Sincerely Sybershot

user: what is the weather
Hal: For the 02838 zipcode area, The forecast calls for Rain at Night weather with a high of 43 and it May get as low as 39 degrees.