Posts: 175
Threads: 43
Joined: Jun 2004
This macro will display the current temperature based on zipcode (US only).
str Src Message zipcode url
zipcode="29455" ;;enter your zipcode here
ARRAY(str) Temp FeelsLike
url.from("http://www.weather.com/weather/local/" zipcode "?lswe=" zipcode "&lwsa=WeatherLocalUndeclared&from=whatwhere")
int MatchSucess
IntGetFile
if findrx(Src "<B CLASS=obsTempTextA>([\d]{1,3})" 0 0 Temp) ;;([\d]{1,3}+)
,if findrx(Src "<B CLASS=obsTextA>Feels Like<BR> ([\d]{1,3})" 0 0 FeelsLike)
,,Message.from("Temperature: " Temp[1] "F" "[]Feels Like: " FeelsLike[1] "F")
,,mes(Message "Current Temperature" "isa")
Matt B
Posts: 576
Threads: 97
Joined: Aug 2007
WOW nice code you got there can be usefull sometimes
Posts: 473
Threads: 33
Joined: Aug 2007
I'm liking this.
Taking on Quick Macros one day at a time
Posts: 473
Threads: 33
Joined: Aug 2007
I was trying to add onto this somewhat and make the 10-Day-Forecast, but I can't get the hang of using findrx.
Taking on Quick Macros one day at a time
Posts: 473
Threads: 33
Joined: Aug 2007
The 10-Day Forecast, complete.
Macro ( 10 Day Forecast ) Trigger ( @11 )
str s message zipcode url
zipcode="48183" ;;<----------Enter your zipcode
url.from("http://www.weather.com/weather/tenday/" zipcode)
IntGetFile url s
ARRAY(str) a
HtmlTableToArray s 12 a 0 2
int i nTDinRow=8
for i 0 a.len nTDinRow
,message.formata("%s %s %s %s %s %s[]" a[i+1] "[]Hi/Lo:" a[i+5] "[]" a[i+2] "[]-----------------------")
mes message "10-Day Forecast" "sa"
Must have function: HtmlTableToArray
Function ( HtmlTableToArray )
;/;
function $HTML VARIANT'tableNameOrIndex [ARRAY(str)&a] [ARRAY(MSHTML.IHTMLElement)&a2] [flags] [str&tableText] ;;flags: 1 get HTML, 2 get all TD elements, including of inner tables
;Gets cells of a HTML table into array.
;HTML - all HTML (page source).
;tableNameOrIndex - table name or 0-based index in the html.
;a - array variable for results. The function creates 1-dimension array where each element is cell text. Can be 0 if not needed.
;a2 - array variable for results. The function creates 1-dimension array where each element is cell object that can be used to get html element within the cell. Can be 0 if not needed.
;tableText - optional str variable that receives whole text of the table. Can be 0 if not needed.
MSHTML.IHTMLDocument2 d; MSHTML.IHTMLDocument3 d3
HtmlParse HTML d d3
IDispatch disp=d3.getElementsByTagName("TABLE").item(tableNameOrIndex); err end "the specified table does not exist"
MSHTML.IHTMLElementCollection cells
if(flags&2)
,MSHTML.IHTMLElement2 t2=disp
,cells=t2.getElementsByTagName("TD")
else
,MSHTML.IHTMLTable2 table=disp
,cells=table.cells
int i nc=cells.length
if(&a) a.create(nc)
if(&a2) a2.create(nc)
for i 0 nc
,MSHTML.IHTMLElement el=cells.item(i)
,if(&a) if(flags&1) a[i]=el.innerHTML; else a[i]=el.innerText
,if(&a2) a2[i]=el
,el=0 ;;without this may be exception in destructors, don't know why
if(&tableText)
,el=disp
,if(flags&1) tableText=el.innerHTML; else tableText=el.innerText
Also, HtmlParse:
Function ( HtmlParse )
function $HTML [MSHTML.IHTMLDocument2&doc2] [MSHTML.IHTMLDocument3&doc3]
;Creates document object model of HTML.
;HTML - HTML.
;doc2, doc3 - variables that, after calling the function, can be used to get parsed HTML information. Can be omitted or 0.
MSHTML.IHTMLDocument2 d._create(uuidof(MSHTML.HTMLDocument))
ARRAY(VARIANT) a.create(1)
a[0]=HTML
d.write(a)
if(&doc2) doc2=d
if(&doc3) doc3=+d
Taking on Quick Macros one day at a time
Posts: 576
Threads: 97
Joined: Aug 2007
Hey i dont have the function "HtmlParse" ???
Posts: 576
Threads: 97
Joined: Aug 2007
Posts: 576
Threads: 97
Joined: Aug 2007
Hey my freind tried using this and doesnt work.....does it only work in the USA?
Posts: 473
Threads: 33
Joined: Aug 2007
Yes, only united states zipcodes.
Taking on Quick Macros one day at a time
Posts: 576
Threads: 97
Joined: Aug 2007
ok...thought that cud be the reason...any way it can be adjusted to use a site where u can enter any zip?
Posts: 473
Threads: 33
Joined: Aug 2007
If you changed the site, then you would have to change the whole code for finding the information.
Taking on Quick Macros one day at a time
Posts: 576
Threads: 97
Joined: Aug 2007
Posts: 1,769
Threads: 410
Joined: Feb 2003
hey matt,
is there a reason for this line?
Src.setclip
it seems it was just for debug but i'm not sure.
thanks.
btw: i use this and the Speak function to get the temp 5 before the hour so i know how to dress before i go to lunch or home.
great work!!!
Posts: 175
Threads: 43
Joined: Jun 2004
Ken,
Sorry I'm replying so late. I haven't played with QM in a while.
Quote:is there a reason for this line?
Src.setclip
it seems it was just for debug but i'm not sure.
You're right Src.setclip was used during debugging. Forgot to delete it. Thanks for the catch.
Matt B
Matt B
Posts: 473
Threads: 33
Joined: Aug 2007
QM Assistant Wrote:
The 10-Day Forecast, complete.
Macro ( 10 Day Forecast ) Trigger ( @11 )
str s message zipcode url
zipcode="48183" ;;<----------Enter your zipcode
url.from("http://www.weather.com/weather/tenday/" zipcode)
IntGetFile url s
ARRAY(str) a
HtmlTableToArray s 12 a 0 2
int i nTDinRow=8
for i 0 a.len nTDinRow
,message.formata("%s %s %s %s %s %s[]" a[i+1] "[]Hi/Lo:" a[i+5] "[]" a[i+2] "[]-----------------------")
mes message "10-Day Forecast" "sa"
Any idea why I get this error now?
Quote:Error (RT) in 10 Day Forecast: invalid index
This shows up right before: Quote:,message.formata("%s %s %s %s %s %s[]" a[i+1] "[]Hi/Lo:" a[i+5] "[]" a[i+2] "[]-----------------------")
Taking on Quick Macros one day at a time
Posts: 11,929
Threads: 138
Joined: Dec 2002
Probably page source HTML has been changed. For example, table index now can be not 12.
Posts: 473
Threads: 33
Joined: Aug 2007
Alright, thanks, i'll give it a look and see if I can find the problem.
Taking on Quick Macros one day at a time
Posts: 11,929
Threads: 138
Joined: Dec 2002
I tried to open the URL in web browser and it says page not found.
Posts: 473
Threads: 33
Joined: Aug 2007
That's the first thing I just checked, but it opens for me.
Taking on Quick Macros one day at a time
Posts: 11,929
Threads: 138
Joined: Dec 2002
Quote:We're sorry, the page you requested was not found on weather.com
Posts: 473
Threads: 33
Joined: Aug 2007
I just put this into a seperate macro, and it works for me.
Macro ( Macro88 )
str s message zipcode url
zipcode="48183" ;;<----------Enter your zipcode
url.from("http://www.weather.com/weather/tenday/" zipcode)
web url 8
Taking on Quick Macros one day at a time
Posts: 473
Threads: 33
Joined: Aug 2007
I tried Matt's version of this, with just current temperature, and his still works. Could this have something to do with the HtmlTables being arrayed?
Taking on Quick Macros one day at a time
Posts: 11,929
Threads: 138
Joined: Dec 2002
urls in code1 and code2 are different
http://www.weather.com/weather/local/29 ... =whatwhere
http://www.weather.com/weather/tenday/48183
If the second url worked but now not, I think the page structure changed. Need to edit the macro.
Posts: 473
Threads: 33
Joined: Aug 2007
I'll take a better look at it when I get some free time.
Taking on Quick Macros one day at a time
Posts: 86
Threads: 27
Joined: Jan 2008
Some reason on the top temp code i get an error
Error in "Macro /240"oMacro: expected 2 to 8 arguments, not 0.
And it highlights IntGetFile
Any ideas on what is wrong?
Posts: 11,929
Threads: 138
Joined: Dec 2002
should be
IntGetFile url Src
Posts: 86
Threads: 27
Joined: Jan 2008
Thanks now it works perfectly
Posts: 576
Threads: 97
Joined: Aug 2007
Im trying to make this tell the Forecast, like if its snowing or rainging or sunny, getting that from the same page as temp.
but for some reason this is not working? any ideas...
Macro
str Src Message Message2 zipcode url
zipcode="08620" ;;enter your zipcode here
str Forecast
url.from("http://www.weather.com/weather/local/" zipcode "?lswe=" zipcode "&lwsa=WeatherLocalUndeclared&from=whatwhere")
IntGetFile url Src
if findrx(Src "<B class=obsTextA>[a-zA-Z]</B>" 0 0 Forecast)
,Message.from("Forecast: " Forecast)
,mes(Message "Current Temperature" "isa")
Posts: 11,929
Threads: 138
Joined: Dec 2002
incorrect regular expression and findrx usage
Posts: 576
Threads: 97
Joined: Aug 2007
Im guessing the problem is in this line
if findrx(Src "<B class=obsTextA>[a-zA-Z]</B>" 0 0 Forecast)
most likely the part [a-zA-Z], i wasnt exactly sure what to use...
it changes between different things ex.
-Sunny
-cloudy
-sunny and cloudy
-snow storm
-rain
-scattered showers
any idea thanks.
|