Split alt_text into function
This commit is contained in:
parent
e6722876bd
commit
551ae7157d
1 changed files with 32 additions and 16 deletions
48
scl.py
48
scl.py
|
@ -117,6 +117,35 @@ 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,
|
||||||
|
@ -174,6 +203,7 @@ 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)
|
||||||
|
@ -188,33 +218,19 @@ 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:
|
||||||
alt_text = "A map showing the location of the outage."
|
pass
|
||||||
|
|
||||||
map_image = map.render()
|
map_image = map.render()
|
||||||
|
|
||||||
|
@ -223,7 +239,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/png",
|
mime_type="image/png",
|
||||||
description=alt_text,
|
description=get_alt_text_string(event),
|
||||||
)
|
)
|
||||||
map_media_post_id = map_media_post["id"]
|
map_media_post_id = map_media_post["id"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue