Overview
The exporters module implements the Factory pattern to provide flexible data export capabilities. It supports exporting job analysis data to both JSON and Excel formats.Architecture
The module uses three key design patterns:- Abstract Base Class:
DataExporterdefines the export interface - Concrete Implementations:
JSONExporterandExcelExporter - Factory Pattern:
ExporterFactoryinstantiates the appropriate exporter
DataExporter
Abstract base class that defines the export interface.Class Definition
Methods
exportar()
Abstract method that all exporters must implement.Dictionary containing job data to export. Expected structure:
termino_busqueda(str): Search term usedtitulo_oferta(str): Job titleurl(str): Job posting URLhabilidades(List[str]): Cleaned skills listfecha_extraccion(str): Extraction timestamp
File path where the exported data should be saved (including file extension)
The file path where data was successfully saved
ExporterFactory
Factory class that instantiates the appropriate exporter based on format.Class Definition
Methods
obtener_exportador()
Static factory method that returns an exporter instance for the specified format.Export format identifier. Supported values:
"json"- Returns a JSONExporter instance"excel"- Returns an ExcelExporter instance
Instance of the appropriate exporter (JSONExporter or ExcelExporter)
Raised if the formato parameter is not “json” or “excel”
JSONExporter
Exporter implementation for JSON format using Python’s built-injson module.
Class Definition
Methods
exportar()
Saves job data to a JSON file with proper UTF-8 encoding and human-readable formatting.Dictionary containing job analysis data
Output file path (should end with
.json)The file path where data was saved
- Uses UTF-8 encoding to properly handle Spanish characters (á, é, í, ó, ú, ñ)
ensure_ascii=Falsepreserves accented charactersindent=4creates human-readable JSON with 4-space indentation- Prints confirmation message to console
ExcelExporter
Exporter implementation for Excel format using pandas and openpyxl.Class Definition
Methods
exportar()
Creates a multi-sheet Excel workbook with organized job data.Dictionary containing job analysis data
Output file path (should end with
.xlsx)The file path where the Excel file was saved
Sheet 1: Información General
Sheet 1: Información General
Contains metadata about the job posting:
| Campo | Valor |
|---|---|
| Término de Búsqueda | User’s search term |
| Título de la Oferta | Job title |
| URL | Job posting URL |
| Fecha de Extracción | Timestamp |
| Total de Habilidades | Count of skills |
Sheet 2: Habilidades
Sheet 2: Habilidades
Numbered list of all extracted skills:
| Número | Habilidad |
|---|---|
| 1 | Python |
| 2 | Django |
| 3 | PostgreSQL |
| … | … |
- Uses
pandas.DataFramefor data structuring - Uses
openpyxlengine for writing.xlsxfiles - Creates professional-looking tables with headers
- Handles missing data with
'N/A'fallback values
Complete Usage Example
Here’s how to use the factory pattern to export data in multiple formats:Dependencies
The Excel exporter requires
pandas and openpyxl. Install with:Best Practices
Use the Factory
Always use
ExporterFactory.obtener_exportador() instead of directly instantiating exporters. This maintains flexibility and follows the Factory pattern.Consistent File Naming
Use timestamps in filenames to prevent overwriting previous exports:
Create Output Directory
Ensure the output directory exists before exporting:
Handle Exceptions
Wrap export calls in try-except blocks to handle file permission errors and disk space issues gracefully.