From 7622d8c68e7c80d38223cc0160813f40319d87b2 Mon Sep 17 00:00:00 2001 From: kaiyuran <73236245+kaiyuran@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:38:38 -0500 Subject: [PATCH] fixed responses + added test --- app.py | 22 +++++++++++++--------- testGet.py | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 testGet.py diff --git a/app.py b/app.py index 98969aa..d095fc1 100644 --- a/app.py +++ b/app.py @@ -159,6 +159,7 @@ def emojify(message): # Donut "donut": "🍩", + "donuts": "🍩", "glazed": "🍩", "glaze": "🍩", "sprinkles": "🍩", @@ -183,7 +184,13 @@ def emojify(message): message = message.split(" ") for word in message: try: - finalMessage.append(word + " " + choiceWordDict[word.lower()]) + formWord = word.lower() + if formWord[-1] == ".": + finalMessage.append(word[:-1] + choiceWordDict[formWord[:-1]]+".") + else: + finalMessage.append(word + choiceWordDict[word.lower()]) + + # print("Emojified word is:",word) except: finalMessage.append(word) @@ -200,23 +207,20 @@ def emojify(message): app = Flask(__name__) -# Define a list of emojis to randomly select from -emojiList = ['😊', '😂', '❤️', '🥰', '😍', '🤔', '😁', '👍', '😎', '🎉', '🔥', '💯', '🌟', '🎈', '✨'] @app.route('/getemoji', methods=['GET']) def get_random_emoji(): # Get the 'letter' parameter from the URL message = request.args.get('message') print(message) - # random_emoji = random.choice(emojiList) - # Return the emoji in JSON format + + final = emojify(message) print(final) - final = jsonify({final: 1}) - # print(final) + final = jsonify({"message": final})# emoji in JSON format + # final = jsonify({final: 1})# emoji in JSON format + return final - # print(type({emojiList[1]: 1})) - # return jsonify({emojiList[1]: 1}) if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/testGet.py b/testGet.py new file mode 100644 index 0000000..53c168f --- /dev/null +++ b/testGet.py @@ -0,0 +1,14 @@ +import requests + +url = "http://127.0.0.1:5000/getemoji" + +params = { + "message": "I love chocolate donuts. I laugh at funny jokes about it. I think it is amazing." +} + +r = requests.get(url, params=params) + +data = r.json() +print(list(data.keys())) +finalMessage = data["message"] +print(finalMessage) \ No newline at end of file