From 873d15b151e89c2c46fc1d762f398a05e653993f Mon Sep 17 00:00:00 2001 From: Liam Steckler Date: Tue, 16 Jan 2024 07:17:12 -0800 Subject: [PATCH] Fix Large color, add geo sanity checks, fix locality --- scl.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scl.py b/scl.py index 3514a0a..26cac52 100644 --- a/scl.py +++ b/scl.py @@ -116,7 +116,7 @@ with Session(engine) as session: outage_color = "#EF4444" else: outage_size = "Large" - outage_color = "991B1B" + outage_color = "#991B1B" if "status" in event: status = event["status"] @@ -189,6 +189,9 @@ with Session(engine) as session: continue print("Existing record not found") + # Fallback location from the SCL API in case one couldn't be reverse geocoded + area_text = event["city"] + try: map = AttribStaticMap( 512, @@ -215,6 +218,12 @@ with Session(engine) as session: center_lat_lon = num2deg(map.x_center, map.y_center, map.zoom) + # Check to make sure the calculated lat and lon are sane enough + # NW Corner + assert center_lat_lon[0] < 48 and center_lat_lon[1] > -122.6 + # SE Corner + assert center_lat_lon[0] > 47.2 and center_lat_lon[1] < -122 + # Zoom level 17 ensures that we won't get any building/POI names, just street names geocode_url = "{nominatim_url}/reverse?lat={lat}&lon={lon}&format=geocodejson&zoom=17".format( nominatim_url=nominatim_url, @@ -243,8 +252,13 @@ with Session(engine) as session: street = geocode["features"][0]["properties"]["geocoding"]["name"] - if "locality" in geocode["features"][0]["properties"]["geocoding"]: - locality = geocode["features"][0]["properties"]["geocoding"] + if ( + "locality" in geocode["features"][0]["properties"]["geocoding"] + and outage_size != "Large" + ): + locality = geocode["features"][0]["properties"]["geocoding"][ + "locality" + ] if locality == "Uptown": locality = "Lower Queen Anne" @@ -298,10 +312,6 @@ with Session(engine) as session: ) map_media_post = None - # Fallback location from the SCL API in case one couldn't be reverse geocoded - if not area_text: - area_text = event["city"] - post_text = """Seattle City Light is reporting a {} outage in {}. Start Date: {} @@ -317,6 +327,12 @@ Cause: {} hashtag_string, ) + print( + "Posting the following to Mastodon, with a post length of {}:\n{}".format( + len(post_text), post_text + ) + ) + mastodon_post_result = mastodon.status_post( status=post_text, media_ids=map_media_post,