Skip to main content
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).


Metadata

Release files for oh-sanitizer 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oh-sanitizer 0.1.10
File Size Uploaded
oh_sanitizer-0.1.10.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for oh-sanitizer 0.1.10
File Interpreter ABI Platform
oh_sanitizer-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 28.8 kB

Release files / oh_sanitizer-0.1.10.tar.gz

Download URL oh_sanitizer-0.1.10.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
42cb52e2f48f83ab7bd1735dd5cdc0baa99bb636ed7b063231399e1d9444db88
BLAKE2b-256 checksum
How to use checksums
a52e58c60d34a7e9f686391c9732e93260e87f5b30f94569ea69a14eeadfaf59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.0

Release files / oh_sanitizer-0.1.10-py3-none-any.whl

Download URL oh_sanitizer-0.1.10-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ebfe81ccb53e8111d55790b3e984608ff53f770b6cb5caab4441c4eef167bd2
BLAKE2b-256 checksum
How to use checksums
2194c67647f8dda4ff62a4b4826ed3db858121ad6408d46f81bddeb867e85de7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

3 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page