Skip to main content

Parses opening hours from various human-readable strings into a standard JSON format

Project description

Python Opening Hours parser

CircleCI codecov Downloads

THIS PROJECT HAS MOVED TO parse-opening-hours. PLEASE USE THAT PACKAGE IF YOU WANT UPDATES

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 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/jsonify-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonify-opening-hours-0.4.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

jsonify_opening_hours-0.4.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file jsonify-opening-hours-0.4.0.tar.gz.

File metadata

  • Download URL: jsonify-opening-hours-0.4.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for jsonify-opening-hours-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7771199154030db8c860adb3a6123740cfa955693e7b99d1bf506686507015ae
MD5 b1ea39d9c2fab52e58a3d9caaeccabdf
BLAKE2b-256 5c029cf3893f68f1f68e98223b68667fc944e1a688fdc3110c39ba066f6992b5

See more details on using hashes here.

File details

Details for the file jsonify_opening_hours-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: jsonify_opening_hours-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for jsonify_opening_hours-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81c414ce3564895d2497e9fef674a963ec31f2f1b9810161fdd1def924bfa63e
MD5 bbb57efafbd5528952e6096a7ce7f0b0
BLAKE2b-256 8b83237d20ce898efa4da0941b787aaa2e8aa99d7a2cc097f8df37b999ed38a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page