Better text cleanup for hashtags
This commit is contained in:
parent
6bcabc55bf
commit
9be93ec7ee
1 changed files with 7 additions and 2 deletions
9
scl.py
9
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue