daspecster / ziptastic

This is a Python API for getting zipcodes
http://daspecster.github.com/ziptastic/
127 stars 17 forks source link

Support full Canadian postal codes #38

Closed curtisgibby closed 12 years ago

curtisgibby commented 12 years ago

Canadian postal codes have two parts, separated by a space (e.g. "M4C 1B5").

The first part (called the Forward Sortation Area -- "M4C") is generally equivalent to the 5-digit ZIP code in the US in that it denotes a town (or section of a larger city), and is what the Ziptastic API currently supports:

http://zip.elevenbasetwo.com/v2/CA/M4C

The second part (called the Local Delivery Unit -- "1B5") drills down to more of a street or block level, much like the last four digits on a US ZIP+4 code.

The major difference between US zip codes and Canadian postal codes is that while I, as an American, couldn't name the full ZIP+4 for any of the homes I've ever lived in, Canadians know and use the full postal code.

Currently, querying the Ziptastic API on the Canadian full postal code (including both the FSA and the LDU) returns an empty result set:

http://zip.elevenbasetwo.com/v2/CA/M4C1B5 (and http://zip.elevenbasetwo.com/v2/CA/M4C+1B5 )

{}

Whereas querying the US API for the ZIP+4, while it's used much less frequently, works correctly:

http://zip.elevenbasetwo.com/v2/US/84040-5111

{"city": "Layton", "state": "Utah", "country": "US"}

Can you make the Canadian version similar to the US, so that an API call using the full postal code returns the same information as the partial 3-character version? Filter the input so that your database query actually only looks for the FSA, no matter what the input looks like. It appears you're already doing something similar to knock down a ZIP+4 to the 5-digit zip code in the US.

curtisgibby commented 12 years ago

Follow up to my comment in issue 37.

curtisgibby commented 12 years ago

I'm not much of a Python coder, but it looks to me that in zipapiserver.py (line 41-ish) you could set the_zip to just the first 3 characters of the_zip if the_country is 'CA'. Then it wouldn't matter if they put in a space (M4C 1B5) or just ran all 6 characters together (M4C1B5) or entered just the first three like you're currently expecting -- they'd all get parsed down to "M4C".