The HTTP API that accepts opening hours data as an input (JSON) and returns a more human readable version of the data formatted using 12-hour clock.
This app features:
- REST API accepting JSON data via POST,
- tests both integration (API) and unit levels (atm coverage 94%),
- build of docker image ready for production deployments,
venvandrequirements.txtfor more stable dependency management,- and Flask 1.1.2 on Python 3.8.
##Answer to Part 1 It was implemented as a possible solution for the Part 1 of the programming task given by Wolt team.
##Answer to Part 2: Actually I found that Epoch time is quite OK for the purpose of defining time within 24h.
However, I'd denormalize input to move day to the level of DayTimeEvents.
- Make sure you have Python 3.8. It might work on earlier v3 but not tested.
- Run following from the project directory
wolt-opening-hours:
pip3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt- Check that tests are passing
pytest- Run either dev or prod (docker) level environment as per following instructions
- Run dev server
FLASK_APP=app python3 -m flask run- Send test data via
curl:
curl -H "Content-Type: application/json" \
-X POST -d '{"monday": [{"type": "open", "value": 32400}, {"type": "close", "value": 72000}]}' \
http://localhost:5000/parse-opening-hours- Server is expected to return
{"data":"Monday: 9 AM - 8 PM\nTuesday: Closed\nWednesday: Closed\nThursday: Closed\nFriday: Closed\nSaturday: Closed\nSunday: Closed"}- Build
#build docker image
docker build -t wolt_oh .
#run container in daemon mode
docker container run -d -p 8080:80 wolt_oh
# follow on logs
docker container logs -f `docker container ls | grep wolt_oh | cut -d' ' -f1`
- Send test data via
curl:
curl -H "Content-Type: application/json" \
-X POST -d '{"monday": [{"type": "open", "value": 32400}, {"type": "close", "value": 72000}]}' \
http://localhost:8080/parse-opening-hours- Server is expected to return
{"data":"Monday: 9 AM - 8 PM\nTuesday: Closed\nWednesday: Closed\nThursday: Closed\nFriday: Closed\nSaturday: Closed\nSunday: Closed"}- Eg: install new python package and update requirements
source venv/bin/activate
pip install pytest-cov==2.11.1
pip freeze > requirements.txt- Get inside of running container
docker exec -it `docker container ls | grep wolt_oh | cut -d' ' -f1` /bin/sh