Skip to content

Commit f72cd57

Browse files
committed
TR updates
1 parent 3c26c35 commit f72cd57

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

replace-string-python/transcript_basic.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
("Blast", "😤"),
1515
("2022-08-24T", ""),
1616
("+00:00", ""),
17-
("[support_tom]", "Tom"),
17+
("[support_tom]", "Agent"),
1818
("[johndoe]", "Client"),
1919
]
2020

21-
new_transcript = transcript
22-
for replacement in replacements:
23-
new_transcript = new_transcript.replace(*replacement)
21+
for old, new in replacements:
22+
transcript = transcript.replace(old, new)
2423

25-
print(new_transcript)
24+
print(transcript)

replace-string-python/transcript_regex.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@
77
[johndoe] 2022-08-24T10:04:03+00:00 : Blast! You're right!
88
"""
99

10-
new_transcript = re.sub(r" blast\w*", "😤", transcript, flags=re.IGNORECASE)
11-
new_transcript = re.sub(r" [-T:\+\d]{25}", "", new_transcript)
12-
new_transcript = re.sub(r"\[support\w*\]", "Agent", new_transcript)
13-
new_transcript = re.sub(r"\[johndoe\]", "Client", new_transcript)
10+
regex_replacements = [
11+
(r" blast\w*", "😤"),
12+
(r" [-T:\+\d]{25}", ""),
13+
(r"\[support\w*\]", "Agent"),
14+
(r"\[johndoe\]", "Client"),
15+
]
1416

15-
print(new_transcript)
17+
for regex_find, regex_replace in regex_replacements:
18+
transcript = re.sub(
19+
regex_find, regex_replace, transcript, flags=re.IGNORECASE
20+
)
21+
22+
print(transcript)

replace-string-python/transcript_regex_callback.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@
1414

1515

1616
def censor_bad_words(message):
17-
output = message
1817
for word in BAD_WORDS:
19-
output = re.sub(rf"{word}\w*", "😤", output, flags=re.IGNORECASE)
20-
return output
18+
message = re.sub(rf"{word}\w*", "😤", message, flags=re.IGNORECASE)
19+
return message
2120

2221

2322
def censor_clients(user):
24-
output = user
2523
for client in CLIENTS:
26-
output = re.sub(rf"{client}", "Client", output)
27-
return output
24+
user = re.sub(rf"{client}", "Client", user)
25+
return user
2826

2927

3028
def sanitize_message(match):
3129
user, _, message = match.groups()
32-
user = user.strip("[]")
33-
user = re.sub(r".*support.*", "Agent", user)
30+
user = re.sub(r"\[.*support.*\]", "Agent", user)
3431
return f"{censor_clients(user)} : {censor_bad_words(message)}"
3532

3633

0 commit comments

Comments
 (0)