Skip to content

Commit 1d46a77

Browse files
Merge pull request #11 from NYPL/log-hours-changes
Log a warning if the earliest library opening and/or the latest library closing changes
2 parents 2dc2104 + f548f35 commit 1d46a77

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2023-06-02 -- v1.0.0
2+
### Added
3+
- Log a warning if the earliest library opening and/or the latest library closing changes
4+
15
## 2023-04-12 -- v0.0.4
26
### Added
37
- Updated output records to use new LocationHours and LocationClosureAlert schema fields

main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def poll_location_hours(logger):
5757
str(row[1])[:-3] if row[1] is not None else row[1],
5858
str(row[2])[:-3] if row[1] is not None else row[2])
5959
for row in raw_redshift_data}
60+
redshift_earliest_open = min(
61+
hours[0] for hours in redshift_dict.values() if hours[0] is not None)
62+
redshift_latest_close = max(
63+
hours[1] for hours in redshift_dict.values() if hours[1] is not None)
6064

6165
logger.info('Polling Refinery for regular location hours')
6266
records = []
@@ -80,6 +84,18 @@ def poll_location_hours(logger):
8084
'regular_open': api_hours['open'],
8185
'regular_close': api_hours['close'],
8286
'date_of_change': str(today)})
87+
if (api_hours['open'] is not None
88+
and api_hours['open'] < redshift_earliest_open):
89+
logger.warning(
90+
('Earliest opening time changed: was {old_open} and is '
91+
'now {new_open}').format(old_open=redshift_earliest_open,
92+
new_open=api_hours['open']))
93+
if (api_hours['close'] is not None
94+
and api_hours['close'] > redshift_latest_close):
95+
logger.warning(
96+
('Latest closing time changed: was {old_close} and is now '
97+
'{new_close}').format(old_close=redshift_latest_close,
98+
new_close=api_hours['close']))
8399
encoded_records = avro_encoder.encode_batch(records)
84100
if os.environ.get('IGNORE_KINESIS', False) != 'True':
85101
kinesis_client.send_records(encoded_records)

0 commit comments

Comments
 (0)