From e68f9c6db945c930f61434a6ca8897e68e9656d8 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 16 Apr 2020 14:58:22 +0100 Subject: [PATCH] Remove hard-coded bank holidays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Looks like someone in the Ministry of Justice has made a nice little Python package of them. I’ve configured it to use the cached holidays that come with the package, rather than going to the GOV.UK website every time we start the app. This should be more reliable, and means we’ll only get updates when we do a version bump (PyUp should keep an eye on this for us). --- app/main/views/feedback.py | 56 +++----------------------------------- requirements-app.txt | 1 + requirements.txt | 1 + 3 files changed, 6 insertions(+), 52 deletions(-) diff --git a/app/main/views/feedback.py b/app/main/views/feedback.py index 00896c1ce..65e2dc106 100644 --- a/app/main/views/feedback.py +++ b/app/main/views/feedback.py @@ -3,6 +3,7 @@ from datetime import datetime import pytz from flask import redirect, render_template, request, session, url_for from flask_login import current_user +from govuk_bank_holidays.bank_holidays import BankHolidays from app import convert_to_boolean, current_service, service_api_client from app.extensions import zendesk_client @@ -19,6 +20,8 @@ from app.models.feedback import ( QUESTION_TICKET_TYPE, ) +bank_holidays = BankHolidays(use_cached_holidays=True) + @main.route('/support', methods=['GET', 'POST']) def support(): @@ -192,58 +195,7 @@ def is_weekend(time): def is_bank_holiday(time): - return time.strftime('%Y-%m-%d') in { - # taken from https://www.gov.uk/bank-holidays.json - # curl https://www.gov.uk/bank-holidays.json | jq '."england-and-wales".events[].date' - "2016-01-01", - "2016-03-25", - "2016-03-28", - "2016-05-02", - "2016-05-30", - "2016-08-29", - "2016-12-26", - "2016-12-27", - "2017-01-02", - "2017-04-14", - "2017-04-17", - "2017-05-01", - "2017-05-29", - "2017-08-28", - "2017-12-25", - "2017-12-26", - "2018-01-01", - "2018-03-30", - "2018-04-02", - "2018-05-07", - "2018-05-28", - "2018-08-27", - "2018-12-25", - "2018-12-26", - "2019-01-01", - "2019-04-19", - "2019-04-22", - "2019-05-06", - "2019-05-27", - "2019-08-26", - "2019-12-25", - "2019-12-26", - "2020-01-01", - "2020-04-10", - "2020-04-13", - "2020-05-08", - "2020-05-25", - "2020-08-31", - "2020-12-25", - "2020-12-28", - "2021-01-01", - "2021-04-02", - "2021-04-05", - "2021-05-03", - "2021-05-31", - "2021-08-30", - "2021-12-27", - "2021-12-28", - } + return bank_holidays.is_holiday(time.date()) def has_live_services(user_id): diff --git a/requirements-app.txt b/requirements-app.txt index e796a1e1c..97dc836ab 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -2,6 +2,7 @@ # with package version changes made in requirements-app.txt ago==0.0.93 +govuk-bank-holidays==0.6 humanize==2.2.0 Flask==1.1.1 Flask-WTF==0.14.3 diff --git a/requirements.txt b/requirements.txt index e4a81f8f8..dc6da3c02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ # with package version changes made in requirements-app.txt ago==0.0.93 +govuk-bank-holidays==0.6 humanize==2.2.0 Flask==1.1.1 Flask-WTF==0.14.3