 |
 |
weather data
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2003
Status:
Offline
|
|
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°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
|
|
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
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2003
Status:
Offline
|
|
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
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2003
Status:
Offline
|
|
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?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|