diff --git a/scl.py b/scl.py index f230123..8f1452d 100644 --- a/scl.py +++ b/scl.py @@ -1,4 +1,5 @@ import io +import re from datetime import datetime from typing import Optional @@ -97,6 +98,10 @@ def classify_event_size(num_people: int) -> dict[str, str | bool]: } +def clean_hashtag_text(hashtag_text: str) -> str: + return re.sub(r"[\W^_]+", "", hashtag_text.title()) + + def get_hashtag_string(event) -> str: city = str() try: @@ -108,12 +113,12 @@ def get_hashtag_string(event) -> str: try: neighborhood = event["neighborhood"] if neighborhood != city: - neighborhood_text = " #{}".format(neighborhood.title().replace(" ", "")) + neighborhood_text = " #{}".format(clean_hashtag_text(neighborhood)) except KeyError: pass hashtag_string = "#SeattleCityLightOutage #SCLOutage{} #{}".format( - neighborhood_text, city.title().replace(" ", "") + neighborhood_text, clean_hashtag_text(city) ) return hashtag_string