Parses opening hours from various human-readable strings into a standard JSON format
Project description
Python Opening Hours parser
This library parses opening hours from various human-readable strings such as "Mon- Fri 9:00am - 5:30pm" into a more standard JSON format that can be processed more easily.
The format
opening_hours = [
{
"day": "monday",
"opens": "9:00",
"closes": "17:00"
},
//..
]
Installation
pip install parse-opening-hours
Usage
The simplest example is just printing the JSON for an opening hours string:
from opening_hours import OpeningHours
print(OpeningHours.parse("Mon- Fri 9:00am - 5:30pm").json())
This should give you the below output:
[
{'day': 'monday', 'opens': '9:00', 'closes': '17:30'},
{'day': 'tuesday', 'opens': '9:00', 'closes': '17:30'},
{'day': 'wednesday', 'opens': '9:00', 'closes': '17:30'},
{'day': 'thursday', 'opens': '9:00', 'closes': '17:30'},
{'day': 'friday', 'opens': '9:00', 'closes': '17:30'}
]
This has been tested using Python 3.8.5
Documentation
In addition to this README, there is some documentation generated from inline documentation comments. This is available at htttps://moralcode.github.io/parse-opening-hours/
Environment variables
Setting the environment variable OH_DEBUG
to a value of Y
will set the root logging level to debug and will cause log entries to appear in stdout for debugging purposes
Troubleshooting
Assumptions
When specifying a time without AM or PM indicators, you may get an error that reads TypeError: Cannot convert a time of unknown type (AM, PM or 24H) without assuming its type.
. To resolve this, pass assume_type=TimeType.AM
when calling the parse()
function. This will use AM in place of an unknown AM or PM designation. In cases like the string "9-5", if the second value in the range (in this case the 5
is smaller than the first (i.e. the 9
) then it will be converted to PM automatically
Tests and Coverage
run pytet and generate coverage database pipenv run pytest --cov=./
show coverage report: pipenv run coverage report
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 parse-opening-hours-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaf88cc19fbe856b0c917efff4c524d03a06d1bfddfb1a240d2cafd240728ea5 |
|
MD5 | ea3e4d43b680490bcfdcf8cfb0b22dba |
|
BLAKE2b-256 | 52e5080876d0a0f9f44f5a304dd80436378fc08efc695e26d0ccbf7bca3eede0 |
Hashes for parse_opening_hours-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d2ed338a61da984ec63ec1aa0e3e59e2a0ab0d79e36b96746eead0a1112e9c8 |
|
MD5 | aa566afa0fc7450c7639b637906561de |
|
BLAKE2b-256 | eb43606feff7c068735ba5cb980677b6a61e70f326ccd36dd10bc36ea64afa30 |