From 0793e7ed507b18240c067762119239eade13946e Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:10:40 -0600 Subject: [PATCH 1/8] Added spellcheck file --- spell_check.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 spell_check.py diff --git a/spell_check.py b/spell_check.py new file mode 100644 index 0000000..fb53d79 --- /dev/null +++ b/spell_check.py @@ -0,0 +1,10 @@ +from autocorrect import Speller + +spell = Speller(lang='en') + +def spell_check(text): + ''' + Spell checks the text + ''' + return spell(text) + From 945d8e38124f99ef2dbbb01d1b39dbba82c52241 Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:19:35 -0600 Subject: [PATCH 2/8] Added Spellcheck to app.py --- .gitignore | 3 ++- app.py | 19 +++++++++++++++---- spell_check.py | 9 +++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d7e8300..2bc45f3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .venv .pytest_cache/ __pycache__ -.vscode \ No newline at end of file +.vscode +.env diff --git a/app.py b/app.py index 70efbd8..0f40543 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,6 @@ ''' from flask import Flask, jsonify, request from models import Experience, Education, Skill - app = Flask(__name__) data = { @@ -48,7 +47,11 @@ def experience(): return jsonify() if request.method == 'POST': - return jsonify({}) + json_data = request.json + if json_data['spell_check']: + json_data = spell_check_json(json_data) + + return jsonify(json_data) return jsonify({}) @@ -61,7 +64,11 @@ def education(): return jsonify({}) if request.method == 'POST': - return jsonify({}) + json_data = request.json + if json_data['spell_check']: + json_data = spell_check_json(json_data) + + return jsonify(json_data) return jsonify({}) @@ -75,6 +82,10 @@ def skill(): return jsonify({}) if request.method == 'POST': - return jsonify({}) + json_data = request.json + if json_data['spell_check']: + json_data = spell_check_json(json_data) + + return jsonify(json_data) return jsonify({}) diff --git a/spell_check.py b/spell_check.py index fb53d79..a526e02 100644 --- a/spell_check.py +++ b/spell_check.py @@ -8,3 +8,12 @@ def spell_check(text): ''' return spell(text) +def spell_check_json(json_data: dict): + ''' + Spell checks the JSON data + ''' + for key, value in json_data.items(): + json_data[key] = spell_check(value) + + return json_data + From 256a12140bcf6ebe5f078ee97c7c1524f913410c Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:31:10 -0600 Subject: [PATCH 3/8] Add test for spell check functionality in education endpoint --- test_pytest.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test_pytest.py b/test_pytest.py index c3d6f08..f640918 100644 --- a/test_pytest.py +++ b/test_pytest.py @@ -3,7 +3,7 @@ ''' from app import app - + def test_client(): ''' Makes a request and checks the message received is the same @@ -72,3 +72,25 @@ def test_skill(): response = app.test_client().get('/resume/skill') assert response.json[item_id] == example_skill + + +def test_spell_check(): + ''' + Test that the spell check endpoint returns a valid response + ''' + + example_education = { + "course": "Engineering", + "school": "NYU", + "start_date": "October 2022", + "end_date": "August 2024", + "grade": "86%", + "logo": "example-logo.png", + "description": "I was head of the debaite team at university", + "spell_check": True + } + + response = app.test_client().post('/resume/education', + json=example_education) + + assert response.json['description'] == "I was head of the debate team at university" \ No newline at end of file From ba7e19a1d662fb7de94ad261dcc668ba9cb4aeab Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:31:23 -0600 Subject: [PATCH 4/8] Removed spell_check json (Redundant) --- spell_check.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spell_check.py b/spell_check.py index a526e02..efbec0a 100644 --- a/spell_check.py +++ b/spell_check.py @@ -7,13 +7,3 @@ def spell_check(text): Spell checks the text ''' return spell(text) - -def spell_check_json(json_data: dict): - ''' - Spell checks the JSON data - ''' - for key, value in json_data.items(): - json_data[key] = spell_check(value) - - return json_data - From 49206f13e0d74683d1a1245574a3a72f3b0982d4 Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:31:33 -0600 Subject: [PATCH 5/8] Added type checking --- app.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 0f40543..77239de 100644 --- a/app.py +++ b/app.py @@ -48,8 +48,8 @@ def experience(): if request.method == 'POST': json_data = request.json - if json_data['spell_check']: - json_data = spell_check_json(json_data) + if json_data.get('spell_check') and isinstance(json_data.get('description'), str): + json_data['description'] = spell_check(json_data['description']) return jsonify(json_data) @@ -65,9 +65,8 @@ def education(): if request.method == 'POST': json_data = request.json - if json_data['spell_check']: - json_data = spell_check_json(json_data) - + if json_data.get('spell_check') and isinstance(json_data.get('description'), str): + json_data['description'] = spell_check(json_data['description']) return jsonify(json_data) return jsonify({}) @@ -83,8 +82,8 @@ def skill(): if request.method == 'POST': json_data = request.json - if json_data['spell_check']: - json_data = spell_check_json(json_data) + if json_data.get('spell_check') and isinstance(json_data.get('description'), str): + json_data['description'] = spell_check(json_data['description']) return jsonify(json_data) From 551e2ccf17185072b337c11de84cf7ef0fcb5c1d Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Wed, 5 Feb 2025 06:58:50 -0600 Subject: [PATCH 6/8] Fixed import issues --- app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.py b/app.py index 77239de..c8bc414 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,8 @@ ''' from flask import Flask, jsonify, request from models import Experience, Education, Skill +from spell_check import spell_check + app = Flask(__name__) data = { From 0934d784be9b9eae3ac86d9d11b69fb96dc922c1 Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Wed, 5 Feb 2025 07:04:09 -0600 Subject: [PATCH 7/8] Moved spell checking to separate endpoint --- app.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/app.py b/app.py index c8bc414..aa9514c 100644 --- a/app.py +++ b/app.py @@ -48,14 +48,19 @@ def experience(): if request.method == 'GET': return jsonify() - if request.method == 'POST': - json_data = request.json - if json_data.get('spell_check') and isinstance(json_data.get('description'), str): - json_data['description'] = spell_check(json_data['description']) + if request.method == 'POST': + return jsonify({}) - return jsonify(json_data) - return jsonify({}) +@app.route('/resume/spell_check', methods=['POST']) +def spell_check(): + json_data = request.json + if json_data.get('description') and isinstance(json_data.get('description'), str): + json_data['description'] = spell_check(json_data['description']) + return jsonify({ + "before": request.json, + "after": json_data + }) @app.route('/resume/education', methods=['GET', 'POST']) def education(): @@ -66,13 +71,7 @@ def education(): return jsonify({}) if request.method == 'POST': - json_data = request.json - if json_data.get('spell_check') and isinstance(json_data.get('description'), str): - json_data['description'] = spell_check(json_data['description']) - return jsonify(json_data) - - return jsonify({}) - + return jsonify({}) @app.route('/resume/skill', methods=['GET', 'POST']) def skill(): @@ -83,10 +82,4 @@ def skill(): return jsonify({}) if request.method == 'POST': - json_data = request.json - if json_data.get('spell_check') and isinstance(json_data.get('description'), str): - json_data['description'] = spell_check(json_data['description']) - - return jsonify(json_data) - - return jsonify({}) + return jsonify({}) From 45ba423c6e1df677ee75099519bb6e088209f6c4 Mon Sep 17 00:00:00 2001 From: jpgtzg <58833781+jpgtzg@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:23:30 -0600 Subject: [PATCH 8/8] Fixing lint --- app.py | 9 +++------ spell_check.py | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 6e4615b..1d287ad 100644 --- a/app.py +++ b/app.py @@ -79,7 +79,7 @@ def experience(index=None): data["experience"].append(experience_obj) return jsonify({"id": len(data["experience"]) - 1}), 201 - except TypeError as e: + except (ValueError, TypeError, KeyError) as e: return jsonify({"error": f"Invalid data format: {str(e)}"}), 400 except Exception as e: return jsonify({"error": f"Internal error: {str(e)}"}), 500 @@ -138,11 +138,8 @@ def skill(): {"id": len(data["skill"]) - 1} ), 201 - except KeyError: - return jsonify({"error": "Invalid request"}), 400 - - except TypeError as e: - return jsonify({"error": str(e)}), 400 + except (ValueError, TypeError, KeyError) as e: + return jsonify({"error": f"Invalid request: {str(e)}"}), 400 return jsonify({}) diff --git a/spell_check.py b/spell_check.py index efbec0a..7269f8b 100644 --- a/spell_check.py +++ b/spell_check.py @@ -1,3 +1,7 @@ +""" +Module for spell checking functionality using autocorrect library. +""" + from autocorrect import Speller spell = Speller(lang='en')