View Full Version : Weather XML Help
abnrange
10-28-2008, 06:13 PM
Sorry if this thread shows up a few time - Had problems posting.
Anyhow, attached is an app I found in the forums. It the Weather Project - I added my key and tested - nothing happens. I tested without the key, which I think is suppose to work from reading the thread. Same result does not work. Is there something missing like a plugin? tried searching for an XML plugin - AMS 7 has then built it!???
Thanks
jassing
10-28-2008, 07:12 PM
yea; doesn't work for me either; but it doesn't complain about a missing plugin.
I'd use any of hte other weather apps over trying to fix this -- this has very limited abilities -- and the weather channel does not update "real time"
abnrange
10-28-2008, 08:25 PM
What other weather apps. I was looking to easily populate current weather with image in my app - Something without advertisments. Any suggestions? Thanks
jassing
10-28-2008, 08:40 PM
Well; if you want to add weather to your current app; that is a bit different than just "getting the weather".
I had produced a COM dll years ago that fetched data from WeatherBug (i wrote it becuase weatherbug was known for spyware) -- while it died a slow death by very low "payment to support" ratio.... The concept is easy.
Look at "weatheroryou.com" -- you can look at hte websites by location and the data -- and then just do an HTTP.Download() or HTTP.Submit() to grab some html -- then parse off the data. Once you "see" the data in the html; you'll see how easy it is to parse.
abnrange
10-28-2008, 08:51 PM
Thanks for the quick response!
You lost me at parse the data. Do you have an example? Can I purchase your COM dll?
jassing
10-28-2008, 09:31 PM
Most websites that post "data" in a regular form use something like (if not exactly) a table. So you just read out the table elements. XML is just another word for HTML; it's just 'data driven' rather than 'attribute driven'.
The weatherbug COM object has long since been abandoned - just wasn't worth the "how do I use a COM object" support calls I was getting for a shareware application that I asked very little for -- ultimately I abandoned it because the shareware model is flawed....
Just open a weather site -- and then "view source" and look for the markers you want (like current temp -- the value like "43c" etc) and look at how you can parse it out.. use string.find() etc.
abnrange
10-29-2008, 09:02 AM
Thanks - I will give that a try!
abnrange
10-29-2008, 09:08 AM
jassing,
How would I parse the current weather from the attached file?
How would you make it display current weather in AMS?
Would I use a label or paragraph?
Sorry, I 'm still learning! Any help would be great. Thanks again
jassing
10-29-2008, 01:25 PM
Giving it a VERY quick review -- you would put it in string; then use String.Find() to look for <b class="obsTextA">
Between that and the next </b> is "Cloudy"
Now look for <b class="obsTempTextA"> Get between that and </b> and you get: 46.8
look for <b class="obsTextA">Cloudy</b> a 2nd time; and then pull out what's between it and </b> and you get:
<b class="obsTextA">Feels Like<br>40°F</b>
so now pull out everything that's between < and > and you get:
Feels LIke 40(Degrees) F
so in total you can get (very easily) Cloudy, 46.8 but feels like 40 detrees F
once you get this simple bit; you can see other paterns in the website looking at random zipcodes -- they rarely change the formats.
abnrange
10-29-2008, 01:41 PM
Jassing,
Remember I'm a newbie - I looked at the help in AMS on strings - I 'm so what confused.
Do you have a sample on how to string the data? I 'm a visual kind of person.
Thanks
Ulrich
10-29-2008, 02:13 PM
Here is an application where you can see how it can be done. There are always different ways to achieve similar results.
Note that I fetch the data directly from the web site before I display the current temperature in the demo application.
Hope this helps.
abnrange
10-29-2008, 03:02 PM
Thanks jassing - Now that I can see the code, I have a better understanding.
Thanks again
abnrange
10-29-2008, 03:10 PM
One more question - Is it possible to load an image depending on weather? If its raining it would load a rain image etc... I did not see where in the source code to parse that data. I see alot of images nothing specific to weather.
Thanks again
abnrange
10-29-2008, 03:19 PM
jassing- I think I found where the image loads from
http://image.weather.com/web/common/wxicons/52/26.gif?12122006
Would it go like this???
string.find (http://image.weather.com/web/common/wxicons/52/26.gif?12122006);
image = http://image.weather.com/web/common/wxicons/52/26.gif?12122006
Image.Load(image)
Or what that load the same gif everytime?
Sorry, still confused!
Ulrich
10-29-2008, 03:54 PM
Here is an altered version of my former example which shows the temperature and the image corresponding to the weather at the chosen location.
Ulrich
abnrange
10-29-2008, 05:24 PM
That's what I was looking for - Thanks for all your help
jassing
10-29-2008, 06:16 PM
I try to give folks a way to learn -- give them a fishing pole & guide them...
so what have you tried?
you'd use the http.download() and that would go to a file.
then use TextFile.ReadToString() to read in that file.
Then use String.Find() and String.Mid() to "pull" the information between the markers.
I'll come up with an example using that website in a few days for you.. but it's a low priority for me.. (I hope you understand)
abnrange
10-29-2008, 07:23 PM
No problem - I appreciate all your time and help!
Thanks again
abnrange
11-09-2008, 03:49 PM
Hello,
Could use some more help with extracting data from text file. I would like to extract the 5 day forecast and display each day into a paragraph. The problem is I do not understand how to get the data from the text file then write it to a string. When looking at the text file I do not know what to look for or how to get the data into ams to display into a paragraph along with image (rain, clouds etc). If someone could show me a sample for one day and where to get the data from the text file - It would be greatly appreciated.
Sorry still learning - Thanks
mwreyf1
11-09-2008, 05:34 PM
Try looking at the section below in your text file for the "OAS_query = " values.
That appears to hold what your looking for.
<!-- MJX config controlled by pif_btrav_tenday_long -->
<SCRIPT LANGUAGE="JavaScript">
<!--
OAS_MJX_on = true; // when true, this allows the MJX ad request to be made
OAS_spoof = '/p/f/r/p/5day/us/nj/504/mays_landing/08330.';
OAS_listpos = 'PageCounter,HeaderSpon,WindowShade,Classified,Pag eSpon,PageSpon2,PdSearch,PageSpon3,PageSpon4,Hidde n1,Hidden2';
OAS_query = 'context=trvl_btrav_tenday&templ1=38&temph2=51&templ2=32&fcond2=cloud_mostly&temph3=51&templ3=33&fcond3=clear_mostly_sunny&';
CM_tag = 'null';
// -->
</SCRIPT>
Just use necessary String commands to parse the data.
abnrange
11-09-2008, 05:51 PM
Here is the code that gets current image and temp.
I 'm still confused on how to do this. How do I get each day temp and image to read to 5 different paragraphs. I'm a visual person - I need to see some type of smaple to understand. The code posted below just confuses me - I don't understand (yet) how to get the data and pass to a string. Any help would be great. Thanks
-- A function that accepts two values and returns one value
function fetchWeather(URL)
StatusDlg.Hide();
HTTP.Download(URL, _TempFolder .. "\\weather.htm", MODE_TEXT, 30, 80)
StatusDlg.Hide();
end
function displayWeather()
if (File.DoesExist(_TempFolder .. "\\weather.htm")) then
html = TextFile.ReadToString(_TempFolder .. "\\weather.htm");
if (string.find(html, '<strong class="obsTempTextA">(.+)°F</strong><br/>') ~= nil) then
temperature = string.sub(html, string.find(html, '<strong class="obsTempTextA">(.+)°F</strong><br/>'));
value = String.Mid(temperature, 30, String.Length(temperature) - 49);
Label.SetText("weather", value .. "°F");
else
Label.SetText("weather", "???");
end
end
end
function fetchImage()
if (File.DoesExist(_TempFolder .. "\\weather.htm")) then
html = TextFile.ReadToString(_TempFolder .. "\\weather.htm");
if (string.find(html, '<div class="cImage"><img width="52" height="52" border="0" src="(.+)" alt=""/><br/>') ~= nil) then
image = string.sub(html, string.find(html, '<div class="cImage"><img width="52" height="52" border="0" src="(.+)" alt=""/><br/>'));
url = String.Mid(image, 65, String.Length(image) - 80);
HTTP.Download(url, _TempFolder .. "\\image.png", MODE_BINARY, 30, 80);
error = Application.GetLastError();
if (error == 0) then
Image.Load("Image1", _TempFolder .. "\\image.png");
end
end
end
end
Ulrich
11-09-2008, 09:59 PM
I 'm still confused on how to do this. How do I get each day temp and image to read to 5 different paragraphs. I'm a visual person - I need to see some type of smaple to understand. The code posted below just confuses me - I don't understand (yet) how to get the data and pass to a string. Any help would be great. Thanks
I believe that "a small sample" was already given. Actually, a whole solution how to search for strings in a document is shown in my code.
The code I presented before showed how to fetch specific information from a specific HTML file. If the file structure changes, or if you want to fetch different informations, the functions won't work without modifications. And to be able to do that, you have to understand what they do. You won't learn just copying somebody's work - try to see what is done, and why. Use the debug window to inspect what the variables contain as the function is processed.
I am showing you now a new project, which demonstrates how to retrieve 5 days of weather forecast. If this page on the Weather.com web site changes its structure, you will have to adjust the code accordingly, or the information won't be found and something might end up missing on the screen.
Ulrich
abnrange
11-09-2008, 10:28 PM
upeters - Thanks again for your help.
I tried to see what and how it was done. Still does not make sense too me.
I still do not understand how you pull the data from the text file.
With time I will learn - Thanks
Imagine Programming
11-10-2008, 12:37 AM
This is our forecast... darn:P this is gonna be a wet week... :(
RizlaUK
11-10-2008, 06:53 AM
lol, i dont need any app or site to tell me im gonner get wet, november in london is always wet, cold n wet and by xmas everything will be coverd in ice
roll on may, thats what i say :yes
Imagine Programming
11-10-2008, 07:41 AM
lol, i dont need any app or site to tell me im gonner get wet, november in london is always wet, cold n wet and by xmas everything will be coverd in ice
roll on may, thats what i say :yes
Amen! it's the same over here:P
RizlaUK
11-10-2008, 09:42 AM
yeah, another *raind off* day
i will jump for joy the day thay invent cement you can use in the rain, its not even like we can use a canvas with all this wind as well, its too much, another day added to the job and not a stich done.
Imagine Programming
11-10-2008, 06:05 PM
well, invent a waterproof layer that can be sprayed on the wet cement:P
abnrange
02-19-2009, 12:57 PM
Hello,
I was wonder if it is possible have an input object so, you can type a ZIP code and it would go fetech the data with images. If so, how can it be done?
I have tried for a few weeks working with parsing data - I don't think I will ever understand how to do it.
Thanks!
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.