| View previous topic :: View next topic |
| Author |
Message |
msnide WeatherBug User
Joined: 25 Feb 2006 Posts: 5
|
Posted: Sat Feb 25, 2006 4:42 am Post subject: API with classic ASP |
|
|
I'm working on a script in ASP classic to pull basic data (at first) from weatherbug but am having trouble. I'm also somewhat new to XML and using the DOMDocument, which doesn't help much.
Does anyone have any basic start-to-finish examples of grabbing say, current temp, using ASP and DOMDocument? As long as I can get started, I think I can roll with it.
Here's my basi code so far. It's just the initial code to get the data, and anything else I'm trying, like xmlDOM.getElementsByTagName("aws:weather") and then trying to get the childnodes of this isn't working. I've gotten a variety of errors, so I can't even boil it down to one problem. (wasnt sure how private the <key> is so I took it out)
[code:1]
URLtoFeed = "http://<key>.api.wxbug.net/getLiveWeather.aspx?acode=<key>&StationID=FTCLN"
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
xmlHttp.Open "Get", URLtoFeed, false
xmlHttp.Send()
xXML = xmlHttp.ResponseText
Set xmlDOM = Server.CreateObject("Microsoft.XMLDOM")
xmlDOM.async = false
xmlDOM.LoadXml(xXML)
[/code:1]
Anyway, any help would be much appreciated. Chris, thanks for sending me the example in email, but that didn't work either. I'll keep working and see what happens.
Matt |
|
| Back to top |
|
 |
msnide WeatherBug User
Joined: 25 Feb 2006 Posts: 5
|
Posted: Sat Feb 25, 2006 5:12 am Post subject: |
|
|
Worked on it a bit more and am having some luck with:
Response.Write "Station: " & xmlDOM.getElementsByTagName("aws:station").item(0).text
Is this the correct way to pull this information? I am a bit confused as to the structure, as I intuitively thought xmlDOM.getElementsByTagName("aws:station").text would work. I am guessing now that the "aws:station" is an element and an item at the same time, but the element doesn't expose the text property?
Sorry this is mostly a DOMDocument thing, but I'm stumbling through this. |
|
| Back to top |
|
 |
cdsloop WeatherBug Guru

Joined: 11 Jan 2006 Posts: 36 Location: Mount Airy, MD
|
Posted: Sat Feb 25, 2006 10:00 pm Post subject: I'll send it out to the group here. |
|
|
I know a few folks here at WeatherBug that have done this type of thing. I will get one of them to jump into the conversation and help out here.
Mark Kamensek is also a good resource. I will see if he wants to join in as well.
Chris |
|
| Back to top |
|
 |
cpotts WeatherBug Guru

Joined: 18 Jan 2006 Posts: 66
|
Posted: Sat Feb 25, 2006 11:50 pm Post subject: ASP Station Parsing |
|
|
Msnide, it's nice to see a developer interested in our API. Here's an asp snippet that I drew up based on what has already been posted.
The code does the following:
[list]
[u][b]Step 1:[/b][/u] Load the Weatherbug XML feed into a DOM object.
[u][b]Step 2:[/b][/u] Search the DOM object looking for nodes with the name 'aws:station'.
[u][b]Step3:[/b][/u] For each 'aws:station' node that is found, print out the predefined attributes (id, city, name, state, zipcode, distance, station-type).[/list:u]
This is just one approach and I'm sure that our other developers could come up with alternative solutions. Be sure to change your ZipCode and enter your API code for the <key>.
Hope this gets you going again. I'm new to all this ASP stuff as well (I'm the Mac programmer here.) Let me know if you need any more examples, I'll try my best to get them to you.
[code:1]<%
URLtoFeed = "http://<key>.api.wxbug.net/getStations.aspx?acode=<key>&ZipCode=40508"
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
xmlHttp.Open "Get", URLtoFeed, false
xmlHttp.Send()
xXML = xmlHttp.ResponseText
Set xmlDOM = Server.CreateObject("Microsoft.XMLDOM")
xmlDOM.async = false
xmlDOM.LoadXml(xXML)
For each xmlNode in xmlDOM.getElementsByTagName("aws:station")
Response.Write "Id: " & xmlNode.getAttribute("id") & "<BR>"
Response.Write "Name: " & xmlNode.getAttribute("name") & "<BR>"
Response.Write "City: " & xmlNode.getAttribute("city") & "<BR>"
Response.Write "State: " & xmlNode.getAttribute("state") & "<BR>"
Response.Write "Zipcode: " & xmlNode.getAttribute("zipcode") & "<BR>"
Response.Write "Distance: " & xmlNode.getAttribute("distance") & "<BR>"
Response.Write "Station-Type: " & xmlNode.getAttribute("station-type") & "<BR><BR>"
Next
%>[/code:1]
Here's the result of using the zip code 40508:
[code:1]Id: LXNPP
Name: Applebee`s Park
City: Lexington
State: KY
Zipcode: 40505
Distance: 2.1512
Station-Type: WeatherBug
Id: LEXTN
Name: Cassidy School
City: Lexington
State: KY
Zipcode: 40502
Distance: 2.2399
Station-Type: WeatherBug
Id: LXNTN
Name: Winburn MS
City: Lexington
State: KY
Zipcode: 40511
Distance: 2.7110
Station-Type: WeatherBug
Id: LXKRC
Name: Keeneland Racetrack
City: Lexington
State: KY
Zipcode: 40510
Distance: 5.3623
Station-Type: WeatherBug
Id: WTVQT
Name: WTVQ-TV
City: Lexington
State: KY
Zipcode: 40509
Distance: 5.4233
Station-Type: WeatherBug
Id: LXNGT
Name: Veterans Park ES
City: Lexington
State: KY
Zipcode: 40515
Distance: 6.3240
Station-Type: WeatherBug
Id: GGTWN
Name: Georgetown MS
City: Georgetown
State: KY
Zipcode: 40324
Distance: 10.5716
Station-Type: WeatherBug
Id: PARIS
Name: Bourbon County MS
City: Paris
State: KY
Zipcode: 40361
Distance: 15.7116
Station-Type: WeatherBug
Id: WINCR
Name: Clark MS
City: Winchester
State: KY
Zipcode: 40391
Distance: 16.0335
Station-Type: WeatherBug
[/code:1] |
|
| Back to top |
|
 |
msnide WeatherBug User
Joined: 25 Feb 2006 Posts: 5
|
Posted: Sun Feb 26, 2006 11:33 am Post subject: |
|
|
Thanks Chris and cpotts....
that code makes sense on the station nodes. Two more questions:
1) how would you cycle through all the nodes in the getLiveWeather data, displaying each's name and their value with units?
When I try the following, I only get the one element:
[code:1]
For each xmlNode in xmlDOM.getElementsByTagName("aws:ob")
Response.Write xmlNode.nodeName & "<BR>"
Next
[/code:1]
2) Is it possible to obtain getLiveWeather for multiple stations at once, and if so is this preferable to querying the info through several separate requests?
Matt |
|
| Back to top |
|
 |
cpotts WeatherBug Guru

Joined: 18 Jan 2006 Posts: 66
|
Posted: Sun Feb 26, 2006 6:35 pm Post subject: LiveWeather XML Structure |
|
|
Msnide, there is only one node per station. Currently, you can only get observations for one station at a time.
Multiple requests would be the route to go, but try to limit the number of calls you are making to 2 or 3. Anything over that will be very, very slow and inefficient.
Also, try the shorter call getLiveCompactWeather to speed things up (but you get less data.) |
|
| Back to top |
|
 |
akumar8_k WeatherBug User
Joined: 11 Mar 2008 Posts: 2
|
Posted: Tue Mar 11, 2008 8:23 am Post subject: What are the tag names in xml |
|
|
| how many xmlDOM.getElementsByTagName |
|
| Back to top |
|
 |
cdsloop WeatherBug Guru

Joined: 11 Jan 2006 Posts: 36 Location: Mount Airy, MD
|
Posted: Wed Apr 08, 2009 10:37 am Post subject: Here is a great example of ASP Classic Implementation |
|
|
[url]http://www.weatherbug.com/api/examples/ASPClassic/ASPweatherExample.zip[/url]
Many thanks to Chris Franklin of Big Rig Media LLC Palm Desert for supplying this example.
[url]www.bigrigmedia.com[/url] |
|
| Back to top |
|
 |
|