File size: 2,503 Bytes
227f173
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from flask import Flask, jsonify, request, flash, redirect, url_for, render_template
from submitter import ResumeSubmitter
from reviewer import ResumeReviewer
from resume_parser import ResumeParser
from logging_config import setup_logging
import json

app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), '..', 'templates'))
app.secret_key = 'supersecretkey'
setup_logging()

@app.route('/v1/resumes/', methods=['POST', 'GET'])
def submit_resume():
    if request.method == 'POST':
        result = ResumeSubmitter().upload_file()
        if os.path.exists(result):
            resume_path = result  # Get the path of the uploaded resume
            try:
                # Redirect to the /v1/reviews/ endpoint with the resume path as a parameter
                return redirect(url_for('get_reviews', path=resume_path))
            except Exception as e:
                app.logger.error("Failed to redirect to /v1/reviews/: %s", str(e))
                return jsonify(message="failed to redirect to reviews page"), 500
        else:
            return jsonify(message=f"failed to submit resume, {result}"), 400
    else:
        return ResumeSubmitter().upload_form()

@app.route("/v1/reviews/<path:path>", methods=['POST', 'GET'])
def get_reviews(path):
    app.logger.debug("Inside get_reviews")
    resume_parser = ResumeParser()
    resume_reviewer = ResumeReviewer()
    parsed_resume_response = resume_parser.parse_text(path)
    
    # Check if the response data is in JSON format
    try:
        # Assuming parsed_resume_response.data contains the JSON string
        parsed_resume_dict = json.loads(parsed_resume_response.data)
    except json.JSONDecodeError:
        app.logger.error("Failed to decode JSON from the response")
        return "Invalid JSON response from parser", 500
    
    # Save the dictionary as JSON file (optional, if you want to save it to a file)
    with open('parsed_resume.json', 'w') as json_file:
        json.dump(parsed_resume_dict, json_file)
    
    # Pass the dictionary to the template
    return render_template("review_output.html", parsed_resume=parsed_resume_dict)

@app.route("/v1/users/<int:id>", methods=['GET'])
def get_user(id):
    return jsonify(message="user retrieved successfully! for given id {}".format(id))

@app.route('/', methods=['GET'])
def greet():
    return render_template('home_page.html')

if __name__ == '__main__':
    app.run()