Compare commits

..

2 commits

30
scl.py
View file

@ -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,