from flask import render_template, request, Blueprint import sqlite3 # for running flask api use this import statements # from .process_pdf import process_pdf # from .process_docx import process_docx # from .extract_resume import extract_resume # for running without flask api use this import statements from utils.process_pdf import process_pdf from utils.process_docx import process_docx from utils.extract_resume import extract_resume import string as s #PATH = r"C:\extraction flask api\netnwork" PATH = "/home/anonymous/Documents/netnwork/" roles = {'fsd': 'Full Stack Developer', 'bd': 'Backend Developer'} ALLOWED_EXTENSIONS = ['pdf', 'docx', 'txt'] def allowed_format(fname): return '.' in fname and fname.split('.')[-1] in ALLOWED_EXTENSIONS sanit = {} sanit['names'] = s.ascii_letters+s.digits+'_.' def sanitize(unsanitized, typ): if unsanitized is None: return None try: return ''.join(c for c in unsanitized if c in sanit[typ]) except: return "Invalid" api = Blueprint('api', __name__) #, template_folder=PATH+'/api/templates', static_folder=PATH+'/api/static', static_url_path=PATH+'/api/static') @api.route('/process_resume', methods=["POST"]) def process_resume(): fields = {} print(request.files) if 'resume' not in request.files: fields['Comment']="No file received" fields['error_code']=400 return fields elif request.files['resume'].filename == '': fields['Comment']="Filename Empty" fields['error_code']=400 return fields file = request.files['resume'] fname = sanitize(file.filename, 'names').lower() if not allowed_format(fname): fields['error_code']=400 fields['Comment']="No file received" return fields if fname.endswith('.pdf'): text_list = txt_from_pdf(file) elif fname.endswith('.docx'): text_list = txt_from_docx(file) elif file.filename.endswith('.txt'): text_list = [str(i.strip(), 'UTF-8') for i in file.readlines()] fields = extract(text_list) #store in sqlite db return fields #automatically calls jsonify