Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > weather data

weather data
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2003
Status: Offline
Reply With Quote
Aug 15, 2003, 01:34 PM
 
I am writing a program (in Cocoa) that needs to access current weather data. I guess the two viable methods of doing so would be to (1) parse the source of a web page, or (2) access a weather web service.

If a website has a text field, for example, for entering your zip code to look up weather information, how do I submit such information and access the resulting web page in my Cocoa app?

How do I do regular expression matching and capturing in Objective-C? For example, if my source contains:

...<br>89&deg;F<br>...

And I want to capture the number "89," how would I do so?

Does anyone know of a free web service through which I can get weather information?

Thanks!
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Aug 15, 2003, 03:32 PM
 
Grab the (old) source for Meteorologist on sourceforge. It doesn't work as well as it used to, and some of my parsing techniques are REALLY obfuscated, but it works.

https://sourceforge.net/projects/heat-meteo/

The way I would get 89 would be:

1) See if there is a pattern in the html where the temperature always occurs, like it's always the first data displayed after a certain sequence of html tags or something
2) Then, using NSScanner or just NSString's rangeOfString methods, find the location of the <b> and the </b>, and calculate the range of the substring between them. That should do the trick. I've encapsulated a lot of this searching into a better class that handles this, and that's probably a good idea for you as well.

If you've got any specific questions, just post here and I'll do my best to answer. Maybe you'll give me a good idea on what do when Meteo 2.0 ever becomes non-vaporware.

Matt Fahrenbacher
     
ewagner  (op)
Fresh-Faced Recruit
Join Date: Aug 2003
Status: Offline
Reply With Quote
Aug 15, 2003, 06:01 PM
 
Matt, I can't seem to find the source code... all I see are binaries.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Aug 15, 2003, 08:05 PM
 
Originally posted by ewagner:
Matt, I can't seem to find the source code... all I see are binaries.
Look in CVS. https://sourceforge.net/cvs/?group_id=78571
     
ewagner  (op)
Fresh-Faced Recruit
Join Date: Aug 2003
Status: Offline
Reply With Quote
Aug 16, 2003, 03:11 PM
 
Matt (and Angus_D), thanks for the help! However, I am wondering if it might be simpler to use perl to do expression matching. That way, with one command (sent to an NSTask), I could extract the weather information that I need. Do you think this would be more efficient?

How do I formulate a perl command that will take in a string, search for a pattern, and return the contents of a captured group?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2