VBA code to read weather

H

HGJ

I am looking for a sample VBA code to read current weather for Ontario from
Canada weather network and display or update the weather table
Thanks
HGJ
 
D

dymondjack

good luck with that one...


Unless some weather software has designed an application to integrate with
access, this probably isn't the easiest task. I have never heard of anything
of the sort, but I guess that doesn't mean it doesn't exist.

If this was a project I had to take on, I would start by looking at a
weather provider's website (weather.com, wunderground, etc) and scanning the
source code of the website. If, by chance, the details of the website are
available through the source code, and not called by functions (the
temp/winds (etc) values would have to be part of the source), you might at
that point be able to get access to save a copy of the page, open it as a
text file, and read through the html and pull the appropriate values. Maybe
some sort of parser can help with that. It would require you to know the
bulk of the website's source code structure, taking into account any changes
that might be made to show different media in the website.

Sounds like fun.

BTW, www.wunderground.com has source code available, and the values are
accessable through the source.

good luck


--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 
D

dymondjack

This one has really sparked my curiousity. As an aspiring pilot, I've lately
been considering an application to handle some of the more common functions
related to aviation (not that there isn't umpteen sources for this already,
but...). Adding a weather moniter into the app would be quite convenient
indeed.

Upon writing my previous post, I checked wunderground to see if the actual
data was available through the source code, and was suprised to find that it
was. Good news. The next question is: can we reliably count on this
information being in the same structure every time? I think so... but we'll
have to make sure. Depending on the weather, a site may have more content on
certain days/times than others, so we'll need to make sure that, in the event
of added content (advisories, etc) that may not be be there on a more normal
basis.

I *think* the structure of the source should not change, but to verify, we
can save copies of different instances of the source in various states of the
site display, and run some comparison utility such as WinDiff to compare the
files and see where the changes might be. This might take a while to make
sure it's downpat, but shouldn't be impossible.

The next big question (the one I don't have any ideas on yet), would be how
to programmatically get a copy of that source code via access (I'm assuming
we'll use some scripting, I don't believe vba has this type of functionality,
but luckily vba can execute the scripts).

So I think the steps would resemble something along the lines of:

1) Open the webpage (easily enough accomplished)
2) Save the webpage to disk for offline use, or
Access the Source Code and save that to disk

#2 is the problem area. If the webpage can be saved for offline use, a copy
of the source is then available from disk. But I'm not sure how to
accomplish this. Possibly some cmdline arguments for IE??

Can anyone supply any feedback on how to accomplish this? I'll search
around some (starting with IE cmds, if possible).

I do wonder about legal implications... I always wondered why the source
code for any website you visit is available to anyone that knows how to find
it. I figured it would be more protected. I'll have to do a bit of research
on this as well.


--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 
D

dymondjack

So, HGJ, I don't have any sample code to offer (it might be a little while
before I get around to it), here's a few things you can quickly throw
together to get started.

Lets say you want the weather forcast for Toronto, which can be found at:

http://www.theweathernetwork.com/weather/caon0696

Pass this link to the API that Stuart kindly provided, and save the file to
a location of your choosing.

Next, open the file through vba's file I/O. Here's a random link pulled
from the inet with an example of what this looks like, in case you are not
aware of the process.

http://www.applecore99.com/gen/gen029.asp

For this example, at the time I saved the source anyway, navigate to line
299 to find your current tempature, line 319 for your windspeed, etc, etc.
If you open the saved webpage in a text or html editor, you will see the
various lines in this area that hold the values.

Again, I assume this structure won't change unless the webmasters put out a
new version of the website, but it would take some monitering to make sure.

So there you go... pull those values from the source, and add them to your
db as you will.


--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 
D

dymondjack

I'm even going to give myself a pat on the back for this one <g>

Good job Jack! Thanks!!

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top