Skip to main content

Converts postcodes to timezones

Reason this release was yanked:

Contained credentials (now invalidated)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

postcode_to_timezone-2024.11.27.1.tar.gz (591.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postcode_to_timezone-2024.11.27.1-py2.py3-none-any.whl (15.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file postcode_to_timezone-2024.11.27.1.tar.gz.

File metadata

File hashes

Hashes for postcode_to_timezone-2024.11.27.1.tar.gz
Algorithm Hash digest
SHA256 17d74c7725545c4190431388bbd424bb7944b78edd18e36212cb552628742d2a
MD5 54005c71654d81b6fbd5161c3c717a15
BLAKE2b-256 28b04b69237256bb2cc0b19187ba4854073daf19e523fbcfce55e806d3e4c1ed

See more details on using hashes here.

File details

Details for the file postcode_to_timezone-2024.11.27.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for postcode_to_timezone-2024.11.27.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 36ee850d9be25adccb3334c1d0a140a2448637521cb0ad86ea7d083f9da07350
MD5 9723534350c1cf38675ee1a6f65083a5
BLAKE2b-256 2b91855cce074ce48786ca18914e4a71b45e240590080e814b8ec251a81aa01e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page