Compare commits

...

2 commits

Author SHA1 Message Date
0265891c92 Merge branch 'main' into edit-posts 2024-11-23 22:15:39 -08:00
551ae7157d Split alt_text into function 2024-11-23 22:12:37 -08:00

48
scl.py
View file

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