Compare commits

..

No commits in common. "edit-posts" and "main" have entirely different histories.

48
scl.py
View file

@ -117,35 +117,6 @@ def get_hashtag_string(event) -> str:
return hashtag_string return hashtag_string
def get_alt_text_string(event) -> str:
try:
street = event["geoloc_street"]
city = event["geoloc_city"]
if city != "Seattle":
city_not_seattle_text = " of {}".format(city)
else:
city_not_seattle_text = ""
try:
locality = event["neighborhood"]
except KeyError:
return "A map showing the location of the outage, centered around {} in {}.".format(
street,
city,
)
if locality == "Uptown":
locality = "Lower Queen Anne"
return "A map showing the location of the outage, centered around {} in the {} area{}.".format(
street,
locality,
city_not_seattle_text,
)
except Exception:
return "A map showing the location of the outage."
def do_initial_post( def do_initial_post(
event, event,
event_class, event_class,
@ -203,7 +174,6 @@ def do_initial_post(
city = geocode["features"][0]["properties"]["geocoding"]["city"] city = geocode["features"][0]["properties"]["geocoding"]["city"]
street = geocode["features"][0]["properties"]["geocoding"]["name"] street = geocode["features"][0]["properties"]["geocoding"]["name"]
event["geoloc_city"] = city event["geoloc_city"] = city
event["geoloc_street"] = street
if city != "Seattle": if city != "Seattle":
city_not_seattle_text = " of {}".format(city) city_not_seattle_text = " of {}".format(city)
@ -218,19 +188,33 @@ def do_initial_post(
if locality == "Uptown": if locality == "Uptown":
locality = "Lower Queen Anne" locality = "Lower Queen Anne"
alt_text = "A map showing the location of the outage, centered around {} in the {} area{}.".format(
street,
locality,
city_not_seattle_text,
)
area_text = "the {} area{}".format(locality, city_not_seattle_text) area_text = "the {} area{}".format(locality, city_not_seattle_text)
event["neighborhood"] = locality event["neighborhood"] = locality
elif "district" in geocode["features"][0]["properties"]["geocoding"]: elif "district" in geocode["features"][0]["properties"]["geocoding"]:
district = geocode["features"][0]["properties"]["geocoding"]["district"] district = geocode["features"][0]["properties"]["geocoding"]["district"]
alt_text = "A map showing the location of the outage, centered around {} in the {} area{}.".format(
street,
district,
city_not_seattle_text,
)
area_text = "the {} area{}".format( area_text = "the {} area{}".format(
district, district,
city_not_seattle_text, city_not_seattle_text,
) )
event["neighborhood"] = district event["neighborhood"] = district
else: else:
alt_text = "A map showing the location of the outage, centered around {} in {}.".format(
street,
city,
)
area_text = city area_text = city
except Exception: except Exception:
pass alt_text = "A map showing the location of the outage."
map_image = map.render() map_image = map.render()
@ -239,7 +223,7 @@ def do_initial_post(
map_media_post = mastodon_client.media_post( map_media_post = mastodon_client.media_post(
map_image_file.getvalue(), map_image_file.getvalue(),
mime_type="image/webp", mime_type="image/webp",
description=get_alt_text_string(event), description=alt_text,
) )
map_media_post_id = map_media_post["id"] map_media_post_id = map_media_post["id"]