Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

zip-lookup function

 [1/3] from: doug::vos::eds::com at: 26-Feb-2001 9:03


I wrote a zip lookup function over the weekend. You provide the zip-code and it returns the "city, state". Only works for USA addresses at this time... However, may be of interest to all since it demonstrates a simple way to grab and re-use information from a web-site. (In this case maps.yahoo.com ) What I need... 1. Try this out and tell me about any bugs, and also suggest any improvements. 2. Need the latest version of an "http-post" to improve this function, by working with a "post" to usps.gov. (no pun intended) Try it out and somebody send me the latest and greatest version of http-post also. REBOL [ Title: "Get city and state from zip-code lookup." Date: 24-Feb-2001 File: %zip-looky.r Author: "Doug Vos" Email: [doug--vvn--net] Purpose: "Allow simple data entry with zip code lookups." ] zip-lookup: func [ {Return a [city state zip] block from a zip.} zip [string! integer!] {A zip code like 56789 or 99999-9999.} /local data xblock i cs city state cs-parts ][ data: load/markup copy/part (read rejoin [ http://maps.yahoo.com/py/maps.py?BFCat=&Pyt=Tmap&addr=&csz= zip ]) 4800 xblock: make block! 100 foreach i data [ if string? i [ if not empty? (trim/lines i) [ append xblock i ] ] ] cs: select xblock "Yahoo! Maps" cs-parts: parse/all cs ";" city: first parse/all (first cs-parts) "," state: first parse/all (second cs-parts) "&" reduce [city state] ] probe zip-lookup "01001" probe zip-lookup "02138" probe zip-lookup 10012

 [2/3] from: doug:vos:eds at: 26-Feb-2001 11:56


try zip-lookup 95482

 [3/3] from: gjones05:mail:orion at: 26-Feb-2001 11:53


From: Vos, Doug
<snip> > 2. Need the latest version of an "http-post" to improve this > function, by working with a "post" to usps.gov. > (no pun intended) <snip>
Hi, Doug, I wrote a similar script a couple of weeks ago for a site. I decided to stick with Yahoo's info because the formatting was already correct. The USPS has the city in all caps, as per the preferred postal regs. However, getting a 'POST is easier than ever now with the newer REBOL releases. You simply use read/custom. Here is a snippet from my prototype code for the USPS: site: http://www.usps.gov/cgi-bin/zip4/ctystzip2? zip: "06501" page: read/custom site reduce ['POST rejoin [{ctystzip=} to-url zip]] parse page [thru "--<BR>" copy city-state to "acceptable"] my-city-state: parse city-state none It returns a 2 to 3 component block depending on the city name. I post this more as an example of the newer read/custom version of 'POST. Hope that this is what you are looking for. --Scott Jones