FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

API with classic ASP

 
Post new topic   Reply to topic    WeatherBug.com Forum Index -> WeatherBug API
View previous topic :: View next topic  
Author Message
msnide
WeatherBug User


Joined: 25 Feb 2006
Posts: 5

PostPosted: Sat Feb 25, 2006 4:42 am    Post subject: API with classic ASP Reply with quote

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:

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)


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
View user's profile Send private message
msnide
WeatherBug User


Joined: 25 Feb 2006
Posts: 5

PostPosted: Sat Feb 25, 2006 5:12 am    Post subject: Reply with quote

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
View user's profile Send private message
cdsloop
WeatherBug Guru
WeatherBug Guru


Joined: 11 Jan 2006
Posts: 36
Location: Mount Airy, MD

PostPosted: Sat Feb 25, 2006 10:00 pm    Post subject: I'll send it out to the group here. Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address
cpotts
WeatherBug Guru
WeatherBug Guru


Joined: 18 Jan 2006
Posts: 66

PostPosted: Sat Feb 25, 2006 11:50 pm    Post subject: ASP Station Parsing Reply with quote

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:

    Step 1: Load the Weatherbug XML feed into a DOM object.
    Step 2: Search the DOM object looking for nodes with the name 'aws:station'.
    Step3: For each 'aws:station' node that is found, print out the predefined attributes (id, city, name, state, zipcode, distance, station-type).

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:
<%

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

%>


Here's the result of using the zip code 40508:

Code:
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
Back to top
View user's profile Send private message Send e-mail
msnide
WeatherBug User


Joined: 25 Feb 2006
Posts: 5

PostPosted: Sun Feb 26, 2006 11:33 am    Post subject: Reply with quote

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:

 For each xmlNode in xmlDOM.getElementsByTagName("aws:ob")
    Response.Write xmlNode.nodeName & "<BR>"
 Next


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
View user's profile Send private message
cpotts
WeatherBug Guru
WeatherBug Guru


Joined: 18 Jan 2006
Posts: 66

PostPosted: Sun Feb 26, 2006 6:35 pm    Post subject: LiveWeather XML Structure Reply with quote

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
View user's profile Send private message Send e-mail
akumar8_k
WeatherBug User


Joined: 11 Mar 2008
Posts: 2

PostPosted: Tue Mar 11, 2008 8:23 am    Post subject: What are the tag names in xml Reply with quote

how many xmlDOM.getElementsByTagName
Back to top
View user's profile Send private message
cdsloop
WeatherBug Guru
WeatherBug Guru


Joined: 11 Jan 2006
Posts: 36
Location: Mount Airy, MD

PostPosted: Wed Apr 08, 2009 10:37 am    Post subject: Here is a great example of ASP Classic Implementation Reply with quote

http://www.weatherbug.com/api/examples/ASPClassic/ASPweatherExample.zip

Many thanks to Chris Franklin of Big Rig Media LLC Palm Desert for supplying this example.

www.bigrigmedia.com
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    WeatherBug.com Forum Index -> WeatherBug API All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
WeatherBug.com topic RSS feed 


Read our Terms of Use. By participating in these discussions you agree to these terms.
© WeatherBug, 2005. All Rights Reserved. Privacy Policy
Powered by phpBB © 2001, 2005 phpBB Group