Skip to main content

A corrector for the 'opening_hours' fields from OpenStreetMap.

Project description

Opening hours sanitizer - A corrector for the 'opening_hours' fields
=========================================================================

If you work with the `opening_hours` fields in OpenStreetMap, you probably need to check somewhere if a field is valid before to parse it, or to do anything with it.

Of course, for simple formats, can do this with regexes, but [specifications](https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification) are so rich that a full regex to handle them is quite impossible.
This is the goal of this tiny module: check if an `opening_hours` field is valid, and try to correct it if it isn't.

In addition to the simple formats, like `Mo-Fr 10:00-20:00`, it can parse and fix almost all shapes of opening hours.
Here is what it can do.

```python
>>> from oh_sanitizer import sanitize_field
>>> print(sanitize_field("mo-fr 10h - 19h00"))
"Mo-Fr 10:00-19:00"
>>> print(sanitize_field("2010 - 2020/2 dec-feb 10:00 am - 12:00 am/1:00 pm-7:00pm"))
"2010-2020/2 Dec-Feb 10:00-12:00,13:00-19:00"
```

**It works both with Python 2 and 3.**

It is so small that you can include it directly into your projet.
You can also install it with PyPi:

$ pip install oh-sanitizer

The `sanitize_field()` function can raise the following exceptions:
- `TypeError` : If the given field is not a string.
- `SanitizeError` : The generic exception of `oh_sanitizer`,
raised when the field can't be parsed (if it is too complex,
or "too much invalid").
- `InconsistentField` : Inheriting from `SanitizeError`,
raised when the field contains an invalid pattern which can't
be corrected automatically.

So, you can simple do this.

```python
from oh_sanitizer import sanitize_field, SanitizeError
field = "mo-fr 10h - 19h00"
try:
sanitized_field = sanitize_field(field)
print("Here is the sanitized field:", sanitized_field)
except SanitizeError:
print("So bad, the field could not be sanitized.")
```

If you want to parse `opening_hours` fields to know, for example, whether a facility is open, OH Sanitizer is NOT what you need.
See the [Humanized Opening Hours](https://github.com/rezemika/humanized_opening_hours) module or its [alternatives](https://github.com/rezemika/humanized_opening_hours#alternatives).


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

oh_sanitizer-0.1.6.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

oh_sanitizer-0.1.6-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file oh_sanitizer-0.1.6.tar.gz.

File metadata

  • Download URL: oh_sanitizer-0.1.6.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.13.0 setuptools/34.3.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.12

File hashes

Hashes for oh_sanitizer-0.1.6.tar.gz
Algorithm Hash digest
SHA256 4cb59291760d688c5480ece1b0eaf9ddeeb33288ebe4b8aa8f336b20413362b1
MD5 5864b35873eabbdddd118ba60724878b
BLAKE2b-256 7f622d38031b988187a5a8f21af2e4c792ba2b80c76894b1a4d85a1e38b9302d

See more details on using hashes here.

File details

Details for the file oh_sanitizer-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: oh_sanitizer-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 28.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.13.0 setuptools/34.3.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.12

File hashes

Hashes for oh_sanitizer-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d937c254453c33c56d0c890cc47d018c7635fc7f7820ed1010a06739ccb17cbc
MD5 551457d531d917531f33ca1ab5114785
BLAKE2b-256 966ca69b744b0bc30542787d4da2d6fc8b4e1d433ad1a47341a17143ded37530

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