Compare commits

..

No commits in common. "b5bb71e09939184ceb80a7ff7ca9f0bfc0735644" and "99e1717f72d39a95b06c2a21282f2fdbe8612f17" have entirely different histories.

30
scl.py
View file

@ -116,7 +116,7 @@ with Session(engine) as session:
outage_color = "#EF4444" outage_color = "#EF4444"
else: else:
outage_size = "Large" outage_size = "Large"
outage_color = "#991B1B" outage_color = "991B1B"
if "status" in event: if "status" in event:
status = event["status"] status = event["status"]
@ -189,9 +189,6 @@ with Session(engine) as session:
continue continue
print("Existing record not found") print("Existing record not found")
# Fallback location from the SCL API in case one couldn't be reverse geocoded
area_text = event["city"]
try: try:
map = AttribStaticMap( map = AttribStaticMap(
512, 512,
@ -218,12 +215,6 @@ with Session(engine) as session:
center_lat_lon = num2deg(map.x_center, map.y_center, map.zoom) 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 # 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( geocode_url = "{nominatim_url}/reverse?lat={lat}&lon={lon}&format=geocodejson&zoom=17".format(
nominatim_url=nominatim_url, nominatim_url=nominatim_url,
@ -252,13 +243,8 @@ with Session(engine) as session:
street = geocode["features"][0]["properties"]["geocoding"]["name"] street = geocode["features"][0]["properties"]["geocoding"]["name"]
if ( if "locality" in geocode["features"][0]["properties"]["geocoding"]:
"locality" in geocode["features"][0]["properties"]["geocoding"] locality = geocode["features"][0]["properties"]["geocoding"]
and outage_size != "Large"
):
locality = geocode["features"][0]["properties"]["geocoding"][
"locality"
]
if locality == "Uptown": if locality == "Uptown":
locality = "Lower Queen Anne" locality = "Lower Queen Anne"
@ -312,6 +298,10 @@ with Session(engine) as session:
) )
map_media_post = None 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 {}. post_text = """Seattle City Light is reporting a {} outage in {}.
Start Date: {} Start Date: {}
@ -327,12 +317,6 @@ Cause: {}
hashtag_string, 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( mastodon_post_result = mastodon.status_post(
status=post_text, status=post_text,
media_ids=map_media_post, media_ids=map_media_post,