From d99f514dfc60f0e494baaf3f29f2cdabd981f203 Mon Sep 17 00:00:00 2001 From: Liam Steckler Date: Sun, 2 Jun 2024 18:30:15 -0700 Subject: [PATCH] Don't inlcude estimated restoration times in the past --- scl.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scl.py b/scl.py index 319ab52..0934fa8 100644 --- a/scl.py +++ b/scl.py @@ -246,17 +246,22 @@ def do_initial_post( map_media_post = None hashtag_string = get_hashtag_string(event) + est_restoration_post_text = str() + if estimated_restoration_time > datetime.now(): + est_restoration_post_text = "\nEst. Restoration: {}\n".format( + estimated_restoration_time.strftime(post_datetime_format) + ) + post_text = """Seattle City Light is reporting a {} outage in {}. -Start Date: {} -Est. Restoration: {} +Start Date: {}{} Cause: {} {}""".format( event_class["size"].lower(), area_text, start_time.strftime(post_datetime_format), - estimated_restoration_time.strftime(post_datetime_format), + est_restoration_post_text, event["cause"], hashtag_string, ) @@ -333,12 +338,14 @@ with Session(engine) as session: updated_entries = [] if estimated_restoration_time != existing_record.estimated_restoration_time: existing_record.estimated_restoration_time = estimated_restoration_time - updated_properties.append("estimated restoration") - updated_entries.append( - "Est. Restoration: {}".format( - estimated_restoration_time.strftime(post_datetime_format) + if estimated_restoration_time > datetime.now(): + # New estimated restoration time is in the future, so likely to be a real time + updated_properties.append("estimated restoration") + updated_entries.append( + "Est. Restoration: {}".format( + estimated_restoration_time.strftime(post_datetime_format) + ) ) - ) if event["cause"] != existing_record.cause: existing_record.cause = event["cause"] updated_properties.append("cause")