Always set city from the geocoding #27

Merged
buckbanzai merged 5 commits from add-neighborhood-hashtag into main 2024-04-20 17:18:38 -07:00
Showing only changes of commit 2a240a1f3f - Show all commits

31
scl.py
View file

@ -99,7 +99,23 @@ def classify_event_size(num_people: int) -> dict[str, str | bool]:
def get_hashtag_string(event) -> str: def get_hashtag_string(event) -> str:
hashtag_string = "#SeattleCityLightOutage #SCLOutage" city = str()
try:
city = event["geoloc_city"]
except KeyError:
city = event["city"]
neighborhood_text = str()
try:
neighborhood = event["neighborhood"]
if neighborhood != city:
neighborhood_text = " #{}".format(neighborhood).title().replace(" ", "")
except KeyError:
pass
hashtag_string = "#SeattleCityLightOutage #SCLOutage{} #{}".format(
neighborhood_text, city.title().replace(" ", "")
)
return hashtag_string return hashtag_string
@ -189,22 +205,27 @@ def do_initial_post(
city_not_seattle_text, 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
elif "district" in geocode["features"][0]["properties"]["geocoding"]: 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( alt_text = "A map showing the location of the outage, centered around {} in the {} area{}.".format(
street, street,
geocode["features"][0]["properties"]["geocoding"]["district"], district,
city_not_seattle_text, city_not_seattle_text,
) )
area_text = "the {} area{}".format( area_text = "the {} area{}".format(
geocode["features"][0]["properties"]["geocoding"]["district"], district,
city_not_seattle_text, city_not_seattle_text,
) )
event["neighborhood"] = district
else: else:
city = geocode["features"][0]["properties"]["geocoding"]["city"]
alt_text = "A map showing the location of the outage, centered around {} in {}.".format( alt_text = "A map showing the location of the outage, centered around {} in {}.".format(
street, street,
geocode["features"][0]["properties"]["geocoding"]["city"], city,
) )
area_text = geocode["features"][0]["properties"]["geocoding"]["city"] area_text = city
event["geoloc_city"] = city
except Exception: except Exception:
alt_text = "A map showing the location of the outage." alt_text = "A map showing the location of the outage."