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
Hashes for postcode_to_timezone-2024.8.7.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e57e6381d0bb3d890281afedd471892a6a4240b49c9fc1afc0b8cd351996216 |
|
MD5 | 74b2c426edbbb5a8572711e3a2b7813f |
|
BLAKE2b-256 | ea1c88a380a480ec64e8849e58788997e915c6fd927cc93b0ae7be68400651a2 |
Hashes for postcode_to_timezone-2024.8.7.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a872e3607eb8fdf85a181d99bb63503193fb29804744e336a1f3d5926adb36e3 |
|
MD5 | e282d00f1ec0f6152b753d8d8136f681 |
|
BLAKE2b-256 | 360ebb158f29d95a136d5e645586647f9870d74c3fcd773d743612fc32cb01c7 |