from reportlab.lib.pagesizes import A4 from reportlab.pdfgen import canvas from reportlab.pdfbase.pdfmetrics import stringWidth import re import os import PyPDF2 def gera_prompt(problema, exemplo_jd): PROMPT = f""" You are a senior technical recruiter specializing in IT roles. Your task is to create a **clear, polished, and professionally formatted job description** suitable for inclusion in a PDF document. The position is intended to hire a professional capable of solving the following problem: **{problema}** Use the following sample job description as a reference: **{exemplo_jd}** **Instructions:** - Reuse relevant sections from the sample job description, especially content about the company, culture, and benefits. - Rewrite and adapt the description to reflect the skills, responsibilities, and qualifications necessary to solve the problem. - Structure the output using **section headers in the format: `** Section Name **`, and well-spaced paragraphs. - Write in clear, concise, and professional English. Avoid overly technical jargon. - The final result must be visually clean, easy to read, and immediately usable in a PDF—no further formatting required. **Use the following structure (if applicable):** ** Job Title: ** [Insert Title] ** Location: ** [Insert Location or "Remote"] ** About the Company ** ** The Opportunity ** ** Responsibilities ** ** Requirements ** ** Preferred Qualifications ** ** What We Offer ** ** How to Apply ** Return only the job title and the formatted job description, between them put a `;;`. Do not include any extra text, headers, or explanations. """ return PROMPT def prompt_compara_CV_jobdescription(CV_texto, jobdescription): PROMPT = f""" You are a senior technical recruiter specialized in assessing candidates for IT positions. Your task is to determine the relevance between a given job description ({jobdescription}) and a candidate's CV ({CV_texto}). Instructions: Extract a list of distinct words or phrases from the CV that directly match or are very strongly align with key skills, technologies, responsibilities, or requirements stated in the job description. Count and return the total number of matched items. Write a concise and objective sentence assessing the candidate’s fit for the role based on the degree of alignment, be very strict. Write a concise and objective list of lacking capabilities from the requirements in the job description, be very strict. Output format (strict): Return the output as a single line, with the following four elements separated by ';;': A comma-separated list of matched words/phrases (no duplicates). An integer indicating the total number of items in the list. A one-sentence professional assessment of candidate-role alignment. A comma-separated list of lacking capabilities (words/phrases) (no duplicates). Important: Do not include any commentary, explanations, or formatting outside of the specified output structure. """ return PROMPT def gerar_pdf(texto: str, caminho_arquivo: str, titulo: str = "Job Title"): largura, altura = A4 margem = 50 largura_texto_max = largura - 2 * margem c = canvas.Canvas(caminho_arquivo, pagesize=A4) c.setTitle(titulo) x = margem y = altura - margem espaco_entre_linhas = 15 # Título da vaga centralizado c.setFont("Helvetica-Bold", 20) titulo_largura = stringWidth(titulo, "Helvetica-Bold", 20) c.drawString((largura - titulo_largura) / 2, y, titulo) y -= espaco_entre_linhas * 2 paragrafos = texto.split('\n') for paragrafo in paragrafos: paragrafo = paragrafo.strip() if not paragrafo: y -= espaco_entre_linhas continue match_titulo_asteriscos = re.fullmatch(r"\*\*\s*(.+?)\s*\*\*", paragrafo) match_titulo_cardinal = re.fullmatch(r"###\s*(.+)", paragrafo) if match_titulo_asteriscos or match_titulo_cardinal: titulo_texto = ( match_titulo_asteriscos.group(1) if match_titulo_asteriscos else match_titulo_cardinal.group(1) ) c.setFont("Helvetica-Bold", 16) if y < margem + 40: c.showPage() y = altura - margem c.drawString(x, y, titulo_texto) y -= espaco_entre_linhas * 2 continue # Renderiza texto com negrito inline c.setFont("Helvetica", 12) palavras = re.split(r'(\*\*.*?\*\*|\s+)', paragrafo) tokens = [] for token in palavras: if not token or token.isspace(): continue if re.fullmatch(r"\*\*.*?\*\*", token): tokens.append(('bold', token[2:-2].strip())) else: tokens.append(('normal', token.strip())) atual_x = x for tipo, texto_token in tokens: fonte = "Helvetica-Bold" if tipo == "bold" else "Helvetica" largura_token = stringWidth(texto_token + " ", fonte, 12) if atual_x + largura_token > largura - margem: y -= espaco_entre_linhas if y < margem + espaco_entre_linhas: c.showPage() y = altura - margem atual_x = x c.setFont(fonte, 12) c.drawString(atual_x, y, texto_token) atual_x += largura_token y -= espaco_entre_linhas * 1.2 c.save() print(f"PDF gerado com sucesso: {caminho_arquivo}") def extrair_texto_pdf(caminho_pdf): texto = "" with open(caminho_pdf, "rb") as arquivo: leitor = PyPDF2.PdfReader(arquivo) for pagina in leitor.pages: texto += pagina.extract_text() + "\n" return texto def extrair_textos_de_diretorio(diretorio="content/"): textos = {} for nome_arquivo in os.listdir(diretorio): if nome_arquivo.lower().endswith(".pdf"): caminho_arquivo = os.path.join(diretorio, nome_arquivo) try: texto = extrair_texto_pdf(caminho_arquivo) textos[nome_arquivo] = texto except Exception as e: print(f"Erro ao processar {nome_arquivo}: {e}") return textos