postcode-to-timezone


Namepostcode-to-timezone JSON
Version 2024.6.4.1 PyPI version JSON
download
home_pageNone
SummaryConverts postcodes to timezones
upload_time2024-06-04 09:43:48
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords open street map time zone
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```python
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:

```sql
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](https://gist.githubusercontent.com/lkopocinski/bd4494588458f5a8cc8ffbd12a4deefd/raw/6bc84f50091852ecfa0ee6ea4b506cabcea1cc52/postal_codes_regex.json)
is stored in `postcode_regex.json`. Actual source not known.

### Timezone definitions

Timezone definitions are used from `timezonefinder` package on
[pypi](https://pypi.org/project/timezonefinder/). The package is licensed under
the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "postcode-to-timezone",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "Koert van der Veer <pypi@ondergetekende.nl>",
    "keywords": "open street map, time zone",
    "author": null,
    "author_email": "Koert van der Veer <pypi@ondergetekende.nl>",
    "download_url": "https://files.pythonhosted.org/packages/e4/f7/9fd90e1cee2c4738da214f22f54762e6ea68a002b32e3d4d01944dd073b0/postcode_to_timezone-2024.6.4.1.tar.gz",
    "platform": null,
    "description": "# Postcode to Timezone\n\nLooks up timezones based on postcode. This is based on the assumption that\npostcodes are roughly following the timezone lines. This is not always true,\nespecially in disputed territories, but it is a good approximation for most\ncases.\n\nThe data used for this lookup is indirectly from OpenStreetMap.\n\n## Usage example\n\n```python\nfrom postcode_to_timezone import get_tz\n\nget_tz('us', '12345')\n```\n\nreturns `'America/Chicago'`\n\n## Building\n\nTo regenerate the lookup table, first obtain a dump of the location_postcode\ntable from a Nominatim database, and compress it to `location_postcode.csv.xz`.\nThen run `python3 generate_lookup_table.py` to generate the lookup table.\n\nActual package is built with `hatch build`, and the package is uploaded to PyPI\nwith `hatch publish`.\n\n## Data sources\n\n### Postcode locations\n\nA dump of the location_postcode table in a Nominatim database. Nominatim\ncreates this database from OpenStreetMap data using the following query:\n\n```sql\nSELECT\n    COALESCE(plx.country_code, get_country_code(ST_Centroid(pl.geometry))) as country_code,\n    pl.address->'postcode' as postcode,\n    COALESCE(plx.centroid, ST_Centroid(pl.geometry)) as geometry\n  FROM place AS pl\n  LEFT OUTER JOIN placex AS plx\n         ON pl.osm_id = plx.osm_id AND pl.osm_type = plx.osm_type\nWHERE\n pl.address ? 'postcode'\n AND pl.geometry IS NOT null\n```\n\nA dump from that table is stored at `location_postcode.csv.xz`.\n\n### Postcode validation\n\nA copy from this [GitHub Gist](https://gist.githubusercontent.com/lkopocinski/bd4494588458f5a8cc8ffbd12a4deefd/raw/6bc84f50091852ecfa0ee6ea4b506cabcea1cc52/postal_codes_regex.json)\nis stored in `postcode_regex.json`. Actual source not known.\n\n### Timezone definitions\n\nTimezone definitions are used from `timezonefinder` package on\n[pypi](https://pypi.org/project/timezonefinder/). The package is licensed under\nthe MIT license.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Converts postcodes to timezones",
    "version": "2024.6.4.1",
    "project_urls": {
        "repository": "https://github.com/kvdveer/postcode-to-timezone"
    },
    "split_keywords": [
        "open street map",
        " time zone"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "998bc9add2fe121846e96afd9497687192e26ba4240ed25606ae8e9a01b6735d",
                "md5": "5a305b4ba3f6293804577dc5ce3bbbf3",
                "sha256": "e09d77a376bda92f9e68f68bf31fcdad68bdf33ce86cfbbe928e464ea398784c"
            },
            "downloads": -1,
            "filename": "postcode_to_timezone-2024.6.4.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5a305b4ba3f6293804577dc5ce3bbbf3",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 14763,
            "upload_time": "2024-06-04T09:43:49",
            "upload_time_iso_8601": "2024-06-04T09:43:49.293898Z",
            "url": "https://files.pythonhosted.org/packages/99/8b/c9add2fe121846e96afd9497687192e26ba4240ed25606ae8e9a01b6735d/postcode_to_timezone-2024.6.4.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e4f79fd90e1cee2c4738da214f22f54762e6ea68a002b32e3d4d01944dd073b0",
                "md5": "5a06ebb86854e8305c6cb8f5f16d4c23",
                "sha256": "89721a6b1bea2fd34c57ddec5331952a6c0940744a43dc5a15845cd70f9cdd8e"
            },
            "downloads": -1,
            "filename": "postcode_to_timezone-2024.6.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5a06ebb86854e8305c6cb8f5f16d4c23",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15752,
            "upload_time": "2024-06-04T09:43:48",
            "upload_time_iso_8601": "2024-06-04T09:43:48.260770Z",
            "url": "https://files.pythonhosted.org/packages/e4/f7/9fd90e1cee2c4738da214f22f54762e6ea68a002b32e3d4d01944dd073b0/postcode_to_timezone-2024.6.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-04 09:43:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kvdveer",
    "github_project": "postcode-to-timezone",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "postcode-to-timezone"
}
        
Elapsed time: 0.42213s