I was using this script
set websitesource to do shell script "curl [url=http://weather.yahoo.com/united-states/california/weaverville-12798193/]http://weather.yahoo.com/united-states/california/weaverville-12798193/"[/url]
tell application "Google Chrome"
try
set todayoffset to text "<b>Today:</b>" in websitesource
set partwebsitesource to (characters todayoffset through 55 of websitesource) as text
on error
set todayoffset to offset of "<strong>Tonight:</strong>" in websitesource
set partwebsitesource to (characters todayoffset through -1 of websitesource) as text
end try
set listoffset to offset of "F" in partwebsitesource
set todayweather to (characters 28 through (listoffset - 1) of partwebsitesource) as text
end tell
A long time ago to fetch weather but since then Yahoo has updated, can someone help me get this working, I couldn’t get it figured it out.
Something like this might be more reliable:
tell application "Google Chrome"
activate
tell window 1 to tell active tab
set URL to "http://weather.yahoo.com/united-states/california/weaverville-12798193/"
repeat until loading is false
delay 0.5
end repeat
set currentTemp to execute javascript "document.getElementsByClassName('day-temp-current temp-f ')[0].childNodes[0].nodeValue"
set todaysHi to execute javascript "document.getElementsByClassName('day-high-low')[0].childNodes[0].nodeValue"
set todaysLow to execute javascript "document.getElementsByClassName('day-temp-low')[0].childNodes[0].nodeValue"
set todaysCond to execute javascript "document.getElementsByClassName('condition first')[0].childNodes[0].nodeValue"
end tell
end tell
return "Condition: " & todaysCond & " Temperature: " & currentTemp & " Range: " & todaysHi & "- " & todaysLow
I would fetch the API response instead of the presentation response. The presentation can be changed any time, as you noticed, while the API haven’t changed at all. You can find more here
DJ makes a good point. An easy way of accessing the API is through YQL.
http://developer.yahoo.com/yql/console/#h=select%20*%20from%20weather.forecast%20where%20woeid%3D12798193
Insert THE REST QUERY into your curl command.
set theWeather to do shell script "curl [url=http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D12798193]http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D12798193"[/url]