Converts postcodes to timezones
Project description
Postcode to Timezone
Looks up timezones based on postcode. This is based on the assumption that postcodes are roughly following the timezone lines. This is not always true, especially in disputed territories, but it is a good approximation for most cases.
The data used for this lookup is indirectly from OpenStreetMap.
Usage example
from postcode_to_timezone import get_tz
get_tz('us', '12345')
returns 'America/Chicago'
Building
To regenerate the lookup table, first obtain a dump of the location_postcode
table from a Nominatim database, and compress it to location_postcode.csv.xz
.
Then run python3 generate_lookup_table.py
to generate the lookup table.
Actual package is built with hatch build
, and the package is uploaded to PyPI
with hatch publish
.
Data sources
Postcode locations
A dump of the location_postcode table in a Nominatim database. Nominatim creates this database from OpenStreetMap data using the following query:
SELECT
COALESCE(plx.country_code, get_country_code(ST_Centroid(pl.geometry))) as country_code,
pl.address->'postcode' as postcode,
COALESCE(plx.centroid, ST_Centroid(pl.geometry)) as geometry
FROM place AS pl
LEFT OUTER JOIN placex AS plx
ON pl.osm_id = plx.osm_id AND pl.osm_type = plx.osm_type
WHERE
pl.address ? 'postcode'
AND pl.geometry IS NOT null
A dump from that table is stored at location_postcode.csv.xz
.
Postcode validation
A copy from this GitHub Gist
is stored in postcode_regex.json
. Actual source not known.
Timezone definitions
Timezone definitions are used from timezonefinder
package on
pypi. The package is licensed under
the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file postcode_to_timezone-2024.8.20.0.tar.gz
.
File metadata
- Download URL: postcode_to_timezone-2024.8.20.0.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f060d6c128675059c09545cf604f88a706c4dbd52732236450dfd8dedcb58cb |
|
MD5 | fba12c406c8247f2908ff71af6cb6e4b |
|
BLAKE2b-256 | 8206a5caded13aa08bd9e8c06ba27b62e9e23dff0b99d2405c4122e670e02710 |
File details
Details for the file postcode_to_timezone-2024.8.20.0-py2.py3-none-any.whl
.
File metadata
- Download URL: postcode_to_timezone-2024.8.20.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b59d46cc0cc6af42b986da66c6504d9d15165c3f516853d2644a9225abab2be |
|
MD5 | 55a31d3606dcf7181c561720aa9b2b5f |
|
BLAKE2b-256 | 8543d955c381578e54a41a5870f8b53280b869254e2e1af56737c7d7acef2039 |