Weather

How do I get the weather and get ot to be said - all with applescript?

Model: PowerMac G4
Browser: Safari 528.16
Operating System: Mac OS X (10.4)

Quick and (extremely) dirty solution:


set weatherurl to "http://weather.yahoo.com/"
set city to "Cupertino CA"

tell application "Safari"
	activate
	make new document with properties {URL:weatherurl}
	repeat
		set docstate to (do JavaScript "document.readyState" in document 1)
		if docstate is "complete" then
			exit repeat
		end if
	end repeat
	delay 3
	do JavaScript "document.forms[2].elements[0].value = \"" & city & "\"" in document 1
	do JavaScript "document.forms[2].elements[1].click()" in document 1
	delay 3
	set websitesource to source of document 1
	close document 1
	set todayoffset to offset of "<strong>Today:</strong>" in websitesource
	set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
	set listoffset to offset of "</li>" in partwebsitesource
	set todayweather to (characters 26 through (listoffset - 1) of partwebsitesource) as text
end tell

tell me
	say "Today's weather in " & city & ": " & todayweather using "Fred"
end tell

Ok, Thanks alot! :smiley: This really helped

hey - I just tried to run the script you gave me and it gives me an error (stated in script) an the weird thing is that is was working for a couple of days, but for some reason it just stopped, so I copied the above code again and put it in a new AppleScript file, but the error remains. What do I do?


set weatherurl to "http://weather.yahoo.com/"
set city to "Cupertino CA"

tell application "Safari"
	activate
	make new document with properties {URL:weatherurl}
	repeat
		set docstate to (do JavaScript "document.readyState" in document 1)
		if docstate is "complete" then
			exit repeat
		end if
	end repeat
	delay 3
	do JavaScript "document.forms[2].elements[0].value = \"" & city & "\"" in document 1
	do JavaScript "document.forms[2].elements[1].click()" in document 1
	delay 3
	set websitesource to source of document 1
	set todayoffset to offset of "<strong>Today:</strong>" in websitesource
	
	(* the following variable pulls up an error: "Can't make characters 0 thru -1 of (websitesource)" if there are any fixes to this, please PM me! *)
	
	set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
	
	(* end known problem area *)
	
	set listoffset to offset of "</li>" in partwebsitesource
	set todayweather to (characters 26 through (listoffset - 1) of partwebsitesource) as text
end tell

tell me
	say "Today's weather in " & city & ": " & todayweather using "Fred"
end tell

Model: Power Mac
AppleScript: AppleScript 1.10.7
Browser: Safari 531.9
Operating System: Mac OS X (10.4)

Hi,

the script searches for the string “Today” in the source, but it could be also “Tonight”


.
set todayoffset to offset of "<strong>Today:</strong>" in websitesource
if todayoffset = 0 then set todayoffset to offset of "<strong>Tonight:</strong>" in websitesource
.

Ok thanks that helps alot… I’ll let you know If I find anymore errors (I doubt it)

thanks again
~curtranhome