I work on and with the web.
From the backend serverside programming, to using javascript to enhance interaction, I like to help people communicate their message.
*Update*
You can see this in action and try it out on www.constructionequipmentguide.com
This took me a few days to get working and it drives me crazy because of how simple it is. My problem is that I tried to do it in Javascript first and my Javascript skills aren’t up to my ASP skills.
It is actually quite simple and here is the code.
*******************
set xmlHTTP = server.createobject("Microsoft.XMLHTTP")
xmlHTTP.open "Get", "http://www.google.com/ig/api?weather=philadelphia,pa", false
xmlHTTP.send()
Set xml = xmlHTTP.ResponseXml
city = xml.documentElement.childNodes(0).firstChild.firstChild.attributes(0).nodeValue
currenttemp = xml.documentElement.childNodes(0).firstChild.nextSibling.childNodes(1).attributes(0).nodeValue
conditionstext = xml.documentElement.childNodes(0).firstChild.nextSibling.childNodes(0).attributes(0).nodeValue
conditionsicon = xml.documentElement.childNodes(0).childNodes(2).childNodes(3).attributes(0).Value
*******************
Then you can just response.write the values where you need them.
Bringing the object back was pretty easy, but traversing the DOM to get the information that I was looking for was a real pain. A combination of Firefox and Firebug made selecting what I needed a lot easier.
You will also notice that I have ‘philadephia, pa’ harcoded into the URL, but where this is being used, I use an IP locator to get the IP address of the user, convert that to a city and state and put that value into the URL, so that users can get their own weather and not mine.
Also ‘conditionsicon’ brings back a relative URL to an icon image for the current conditions. If anyone has a list of all possible conditions that would be amazingly helpful.
Tags: ASP, Code, programming, Web
This entry was posted on Thursday, July 30th, 2009 at 1:57 pm and is filed under ASP, Code, Web. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
StephenCollins.me is proudly powered by WordPress 3.0 Entries (RSS) Comments (RSS).