Better text cleanup for hashtags
Some checks failed
ci/woodpecker/push/lint Pipeline failed
ci/woodpecker/push/vulnerability-scan Pipeline was successful

This commit is contained in:
Liam Steckler 2025-05-03 16:35:03 -07:00
parent 6bcabc55bf
commit 9be93ec7ee

9
scl.py
View file

@ -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