Fix Large color, add geo sanity checks, fix locality
This commit is contained in:
parent
eaa32c6987
commit
873d15b151
1 changed files with 23 additions and 7 deletions
30
scl.py
30
scl.py
|
@ -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,6 +189,9 @@ 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,
|
||||||
|
@ -215,6 +218,12 @@ 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,
|
||||||
|
@ -243,8 +252,13 @@ with Session(engine) as session:
|
||||||
|
|
||||||
street = geocode["features"][0]["properties"]["geocoding"]["name"]
|
street = geocode["features"][0]["properties"]["geocoding"]["name"]
|
||||||
|
|
||||||
if "locality" in geocode["features"][0]["properties"]["geocoding"]:
|
if (
|
||||||
locality = geocode["features"][0]["properties"]["geocoding"]
|
"locality" in 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"
|
||||||
|
|
||||||
|
@ -298,10 +312,6 @@ 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: {}
|
||||||
|
@ -317,6 +327,12 @@ 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,
|
||||||
|
|
Loading…
Reference in a new issue