Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Variables Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 16 2002 at 08:48 | IP Logged Quote TonyNo

Is there any difference between the LOCALx and MACROx variables? I'm having trouble with the Get Weather macro. I pull out the temp and humidity values fine, but, the forecast part does not work.

Thanks,

Tony

Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: November 17 2002 at 14:05 | IP Logged Quote dhoward

Tony,

Long time no hear!

There is no difference between the LOCALx and MACROx variables other than the fact that support for the MACROx variables will be dropped in the very near future so be sure and update your database.

I checked the Get Weather macro out and found what the problem was.  Apparently Weather Underground has changed their page a little bit and the data for the forecast is past the first 30000 characters.  The first line of the Get Weather macro takes the leftmost 30000 characters of the returned HTML to work with.  I was able to fix it by changing the 30000 to 50000.

If you want to play with the WSH capabilities, Ive posted the Get Weather macro rewritten as a WSH file below:

sub getweather(zipcode)
 dim s_html,s_weather,s_temp,l_pos1,l_pos2,l_return

 s_html = left(ph.geturl("http://www.weatherunderground.com/cgi-bin/findweather/getForecast?query=" & zipcode),50000)
 l_return = int(mid(s_html,10,3))
 if l_return <> 200 then
  msgbox "Unable to get URL.  Return value is: " & l_return
  return
 end if
 l_pos1 = instr(1,s_html,"<td>Temperature</td>")
 l_pos2 = instr(l_pos1,s_html,"<b>") + 3
 s_temp = mid(s_html,l_pos2,3)
 if not isnumeric(mid(s_temp,3,1)) then
  s_temp = left(s_temp,2)
 end if
 s_weather = "The temperature is " & s_temp & " degrees. "
 l_pos1 = instr(l_pos2,s_html,"<td>Humidity</td>")
 l_pos2 = instr(l_pos1,s_html,"<b>") + 3
 s_temp = mid(s_html,l_pos2,3)
 if not isnumeric(mid(s_temp,3,1)) then
  s_temp = left(s_temp,2)
 end if
 s_weather = s_weather & "The Humidity is " & s_temp & " percent. "
 l_pos1 = instr(l_pos2,s_html,"<b>Forecast for ")
 l_pos1 = instr(l_pos1,s_html,"<td align=left><b>") + 18
 l_pos2 = instr(l_pos1,s_html,"</b>")
 s_weather = s_weather & "The forecast for " & mid(s_html,l_pos1,l_pos2 - l_pos1) & " is "
 l_pos1 = l_pos2 + 9
 l_pos2 = instr(l_pos1,s_html,"</td>")
 s_weather = s_weather & mid(s_html,l_pos1,l_pos2 - l_pos1)
 do
  l_pos1 = instr(1,s_weather,"winds")
  if l_pos1 = 0 then exit do
  s_weather = left(s_weather,l_pos1 - 1) & "wins" & mid(s_weather,l_pos1 + 5)
 loop
  
 ph.tts s_weather
end sub

You can call this script from a macro or sendkeys by executing the function below:

ph_runscript_1("getweather.vb","vbscript",1,0,"getweather","32707")

Substitute your zipcode for 32707.  The above line also assumes that you saved the getweather script into a file named "getweather.vb".

Hope this helps.

Dave.

 

Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 17 2002 at 17:48 | IP Logged Quote TonyNo

Cool! Thanks, Dave. I'll have to start playing with the scripts.

Tony

Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 18 2002 at 20:15 | IP Logged Quote TonyNo

Just an addition...

I added a section to the macro/script that replaces any ellipses ("...") with a period. I got sick of hearing the system pause and then say, "dot"!

Tony

Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 28 2006 at 14:43 | IP Logged Quote theowl

It appears that the website has changed again since this WSH. Here's my version of the same script with a few updates...

sub getweather(zipcode)
dim s_html, s_weather, s_temp, l_pos1, l_pos2, l_return

s_html = left(ph.geturl("http://www.weatherunderground.com/cgi-bin/fi ndweather/getForecast?query=" & zipcode),100000)
l_return = int(mid(s_html,10,3))
if l_return <> 200 then
msgbox "Unable to get URL. Return value is: " & l_return
return
end if
l_pos1 = instr(1,s_html, "</b> °F")-10
l_pos2 = instr (l_pos1,s_html,"<b>") + 3
s_temp = mid(s_html,l_pos2,3)
if not isnumeric(mid(s_temp,3,1)) then
s_temp = left(s_temp,2)
end if
s_weather = "The temperature is " & s_temp & " degrees. "
l_pos1 = instr(l_pos2,s_html,">Humidity:</td>")
l_pos2 = instr(l_pos1,s_html,"#996;") + 7
s_temp = mid(s_html,l_pos2,3)
if not isnumeric(mid(s_temp,3,1)) then
s_temp = left(s_temp,2)
end if
s_weather = s_weather & "The Humidity is " & s_temp & " percent. "
l_pos1 = instr(l_pos2,s_html,">Forecast for ") +14
l_pos2 = instr(l_pos1,s_html,"</td>")
s_weather = s_weather & "The forecast for " & mid(s_html,l_pos1,l_pos2 - l_pos1) & " "
l_pos1 = instr(l_pos2,s_html,"<div id=""b"">") +12
l_pos2 = instr(l_pos1,s_html,"</div>")
s_weather = s_weather & mid(s_html,l_pos1,l_pos2-l_pos1) & " is "
l_pos1 = instr(l_pos2,s_html,"<div>") +5
l_pos2 = instr(l_pos1,s_html,"</div>")
s_weather = s_weather & mid(s_html,l_pos1,l_pos2-l_pos1)
rem Extended Forecast
l_pos1 = instr(l_pos2,s_html,"<div id=""b"">") +12
l_pos2 = instr(l_pos1,s_html,"</div>")
s_weather = s_weather & mid(s_html,l_pos1,l_pos2-l_pos1) & " should be "
l_pos1 = instr(l_pos2,s_html,"<div>") +5
l_pos2 = instr(l_pos1,s_html,"</div>")
s_weather = s_weather & mid(s_html,l_pos1,l_pos2-l_pos1)

do
l_pos1 = instr(1,s_weather,"winds")
if l_pos1 = 0 then exit do
loop

ph.tts s_weather
end sub

--
I have a GETWEATHER macro with a single function line that reads:

ph_runscript_1("C:\Program Files\powerhome\scripts\getweather.vbs","vbscript",1,5000,"g etweather","90210")

A trigger on C16-ON calling the macro completes the job.
Back to Top View theowl's Profile Search for other posts by theowl
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: February 28 2006 at 15:19 | IP Logged Quote dhoward

Thanks for posting the updated code for us.

Also, be sure and check out the NEW ph_regex functions. They make this type of search and scan operation much simpler. Ive been meaning to do it but just havent had the time with the work being done for Insteon support.

They havent been added to the vbscript module yet, but you can always call them by passing them in with the ph.formula function.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
theowl
Groupie
Groupie
Avatar

Joined: February 24 2006
Location: United States
Online Status: Offline
Posts: 59
Posted: February 28 2006 at 23:49 | IP Logged Quote theowl

Your Welcome...and wouldn't you know that the instant I post the updated code, the site changes!?!

Old line:
l_pos2 = instr(l_pos1,s_html,"#996;") + 7

New line:
l_pos2 = instr(l_pos1,s_html,"<nobr><b>") + 9

Thanks for the ph_regex suggestion, I'll take a look at that when time allows. I plan on having a lot more website access macros and scripts, so it should come in real handy! First, I have to figure out why the Activehome controller went nuts again and took out all automation controls. I'll be SO glad when I don't have to rely on that thing for remote reception.    
Back to Top View theowl's Profile Search for other posts by theowl
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum