Skip to main content

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": "5: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 JsonOpeningHours

print(JsonOpeningHours.parse("Mon- Fri 9:00am - 5:30pm"))

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

Tests

run python3 -m unittest

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.1.0.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

jsonify_opening_hours-0.1.0-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

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