From b3474e24c97a02e5740c84b64c848e002c55feb3 Mon Sep 17 00:00:00 2001 From: Liam Steckler Date: Wed, 31 Jan 2024 21:30:44 -0800 Subject: [PATCH] Revert to looking up all, only post if previously posted --- scl.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/scl.py b/scl.py index 867994f..bc17e58 100644 --- a/scl.py +++ b/scl.py @@ -409,10 +409,8 @@ with Session(engine) as session: session.add(new_outage_record) session.commit() - lookup_active_outages_statement = ( - select(SclOutage) - .where(SclOutage.no_longer_in_response_time == None) - .where(SclOutage.most_recent_post_id != None) + lookup_active_outages_statement = select(SclOutage).where( + SclOutage.no_longer_in_response_time == None ) for active_outage in session.scalars(lookup_active_outages_statement): if ( @@ -420,15 +418,15 @@ with Session(engine) as session: and event ): # Event ID no longer exists in response - post_result = mastodon.status_post( - status="This outage is reported to be resolved.\n\n#SeattleCityLightOutage #SCLOutage #SCLOutage{}".format( - active_outage.outage_user_id - ), - in_reply_to_id=active_outage.most_recent_post_id, - visibility="public", - language="en", - ) - - active_outage.most_recent_post_id = post_result["id"] + if active_outage.most_recent_post_id: + post_result = mastodon.status_post( + status="This outage is reported to be resolved.\n\n#SeattleCityLightOutage #SCLOutage #SCLOutage{}".format( + active_outage.outage_user_id + ), + in_reply_to_id=active_outage.most_recent_post_id, + visibility="public", + language="en", + ) + active_outage.most_recent_post_id = post_result["id"] active_outage.no_longer_in_response_time = datetime.now() session.commit()