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 jsonify-opening-hours
Usage
The simplest example is just printing the JSON for an opening hours string:
from parse_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
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
Build and Release
This is pretty much here so I can copy-paste the commands to make a new release.
build: python setup.py sdist bdist_wheel
check: twine check dist/*
upload: twine upload dist/*
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
Built Distribution
Hashes for jsonify-opening-hours-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75a97e0eb519b24f3e59a7063ecf1ad465bb220d973a62d991b2601f6487ab80 |
|
MD5 | 2108388b2d2da288c67239e0c2ba10c0 |
|
BLAKE2b-256 | 643e0559171008c8a0aa47abb96d6dcc3bbf28e49069efa724919d6328722661 |
Hashes for jsonify_opening_hours-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e6e5270dbea813b02f2135d170666886ffb203cbe7a5a57140934488377f3d8 |
|
MD5 | 3394bcc160b21cfc84f66a8a490192e6 |
|
BLAKE2b-256 | 89efa932465d6628074e0bbb74b5d0bd8274552b7b7497e0c4b79c841848762e |