From c9c29ffeec485c0d97ace782b78ad92264ea4efe Mon Sep 17 00:00:00 2001 From: kaiyuran <73236245+kaiyuran@users.noreply.github.com> Date: Wed, 20 Nov 2024 18:23:24 -0500 Subject: [PATCH] fix punctuation handling --- app.py | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 567043c..691879e 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,12 @@ import random def emojify(message): choiceWordDict = { + "hello": "👋", + "hi": "👋", + "hey": "👋", + "greetings": "👋", + "goodbye": "👋", + #happy face "happy": "😊", "joy": "😊", @@ -253,8 +259,36 @@ def emojify(message): "sunflower": "🌻", "daisy": "🌼", "hibiscus": "🌺", + "work": "🏢", + "office": "🏢", + "building": "🏢", + "construction": "🏗️", + "site": "🏗️", + "school": "🏫", + "university": "🏫", + "college": "🏫", + "hospital": "🏥", + "clinic": "🏥", + "doctor": "👩‍⚕️", + "nurse": "👩‍⚕️", + "therapist": "👩‍⚕️", + "healthcare": "👩‍⚕️", + "police": "👮", + "cop": "👮", + "law": "👮", + "enforcement": "👮", + "officer": "👮", + "movie": "🎥", + "film": "🎥", + "camera": "🎥", + "movies": "🎥", + "cinema": "🎥", + "theater": "🎭", + "drama": "🎭", + "acting": "🎭", + "perform": "🎭", } - + puncList = [".",",","!","?",";"] message = message.strip('"') message = message.strip("'") finalMessage = [] @@ -263,9 +297,12 @@ def emojify(message): for word in message: try: formWord = word.lower() - if formWord[-1] == ".": - finalMessage.append(word[:-1] + (choiceWordDict[formWord[:-1]] * random.randint(1,3)) +".") - else: + done = False + for punctuation in puncList: + if formWord[-1] == punctuation: + finalMessage.append(word[:-1] + (choiceWordDict[formWord[:-1]] * random.randint(1,3)) +punctuation) + done = True + if not done: finalMessage.append(word + choiceWordDict[word.lower()]) @@ -303,5 +340,5 @@ def get_random_emoji(): if __name__ == '__main__': #app.run(debug=True) - app.run(port=33303) - # app.run(host='0.0.0.0', port=33303) \ No newline at end of file + # app.run(port=33303) + app.run(host='0.0.0.0', port=33303) \ No newline at end of file