Spaces:
Sleeping
Sleeping
Randy Mustelier Rivero
feat: completar Fase 1 - URL normalizer, adapters YAML, anti-scraping, endpoint y 36 tests
e597ad1 |
Download CHECKPOINT.md from Randolo/novasearch: direct link, hf CLI and curl.
- Browser
- Download file 9.38 kB
-
https://huggingface.co/spaces/Randolo/novasearch/resolve/main/CHECKPOINT.md
- Command line
-
hf download hf://spaces/Randolo/novasearch/CHECKPOINT.md
-
curl -L -o CHECKPOINT.md https://huggingface.co/spaces/Randolo/novasearch/resolve/main/CHECKPOINT.md
9.38 kB
| # πΈοΈ Checkpoint: ScrapperGenΓ©rico | |
| **Γltima actualizaciΓ³n:** 2026-06-02 | |
| **Repo remoto:** `https://github.com/randoloc/Sistema-de-Scraping-Parametrizado` | |
| --- | |
| ## β Estado actual | |
| | Componente | Estado | Notas | | |
| |-----------|--------|-------| | |
| | **Servicio FastAPI** (MΓ³dulo 1) | β Funcionando | `http://127.0.0.1:8000` β health, scraping, resultados, entregas | | |
| | **Email Delivery** (SMTP Gmail) | β Configurado | `.env` con credenciales, carga vΓa `python-dotenv` | | |
| | **Admin core** (client, models, repo) | β Funcionando | Cliente HTTP, modelos de datos, SQLite local | | |
| | **GUI PySide6+QML** (MΓ³dulo 2) | β Corregida | Padding bugs en Rectangles β Pane. UI completa visible | | |
| | **PythonBridge** (slots PythonβQML) | β Completo | Dashboard, scraping, resultados, entregas, historial | | |
| | **QML UI** | β Wireado | Todos los botones conectados al scraper real | | |
| | **Historial SQLite** | β Persistente | `~/.scrapper_generico/admin.db` | | |
| | **Tests** | β **96/96 pasando** | 75 unitarios + 13 integraciΓ³n + 8 nuevos archivos test | | |
| | **Fase 1 β Base GenΓ©rica** | β **Completada** | URL normalizer, adapters YAML, anti-scraping, endpoint, tests | | |
| | **Adapters API** | β `/api/adapters` | Listado con filtro por vertical, estructuras Pydantic | | |
| | **README** | β Creado | En raΓz del repo | | |
| | **Repo GitHub** | β Creado | `randoloC/Sistema-de-Scraping-Parametrizado` | | |
| --- | |
| ## π Γltimas sesiones | |
| ### SesiΓ³n 4 (2026-06-02) β Fase 1 Completa: Endpoint adapters + 36 tests nuevos | |
| - β Agregado `GET /api/adapters` con filtro opcional `?vertical=` | |
| - β Escritos 36 tests nuevos: | |
| - 9 tests para `normalize_url()` (con/sin protocolo, vacΓa, invΓ‘lida) | |
| - 5 tests para `UARotator` (rotaciΓ³n, circular, pool default) | |
| - 4 tests para `RetryPolicy` (Γ©xito, timeout, retry con Γ©xito, HTTP errors) | |
| - 5 tests para `DomainDelay` (primera request, espera, suficiente tiempo, custom delay, dominios distintos) | |
| - 9 tests para `AdapterLoader` (YAML vΓ‘lido/invΓ‘lido, filtros, count) | |
| - 4 tests para endpoint `/api/adapters` (listado, filtro vertical, estructura) | |
| - β Suite completa: **96 tests, 0 fallas** (antes 60) | |
| - β Todos los tasks de Fase 1 marcados como completados en `openspec/` | |
| ### SesiΓ³n 3 (2026-06-02) β Email delivery + Fix QML + Sistema funcionando | |
| - β Corregido bug de `padding` en QML (Rectangle no tiene `padding` en QtQuick 2.15) | |
| - `RowLayout` β `anchors.margins` | |
| - `Rectangle` β `Pane` (que sΓ soporta `padding`) | |
| - ToolBar tiene `padding` nativamente | |
| - QML carga sin errores: 1 root object, 0 syntax errors | |
| - β Configurado email delivery vΓa `.env`: | |
| - Creado `.env` con credenciales SMTP Gmail | |
| - Modificado `EmailDelivery` para leer de `os.getenv()` con defaults | |
| - Agregado `load_dotenv()` en mΓ³dulo de email | |
| - β Prueba completa exitosa: | |
| - Scraping `http://httpbin.org/html` β 1 item extraΓdo β | |
| - PΓ‘gina web generada β 8,139 caracteres β | |
| - Email enviado a `randolo92cromix@gmail.com` β `email_sent: true` β | |
| - β ComunicaciΓ³n M1βGUI probada y funcionando | |
| ### SesiΓ³n 2 β App funcional + Tests en vivo | |
| - β Instalado `PySide6-Essentials` (77.5 MB) | |
| - β Prueba en vivo del admin client contra FastAPI | |
| - β Creado README.md y pusheado a GitHub | |
| ### SesiΓ³n 1 β App de Admin + Tests de IntegraciΓ³n | |
| - β PythonBridge + QML + 8 tests de integraciΓ³n | |
| - β Arquitectura documentada | |
| --- | |
| ## π§ͺ CΓ³mo probar | |
| ```bash | |
| # 1. Configurar credenciales (copiar .env.example a .env y completar) | |
| cp .env.example .env | |
| # 2. Iniciar servicio FastAPI | |
| uvicorn modulo_1_servicio.main:app --reload --port 8000 | |
| # 3. En otra terminal, abrir la app desktop | |
| python -m modulo_2_admin.main | |
| # 4. O ejecutar tests | |
| python -m pytest tests/ -v --tb=short | |
| # 5. O probar scraping + email delivery desde consola | |
| python -c " | |
| from modulo_2_admin.core.client import ScrapperClient | |
| client = ScrapperClient('http://127.0.0.1:8000') | |
| # Scrape | |
| resp = client.run_scrape({ | |
| 'source': 'http://httpbin.org/html', | |
| 'source_type': 'web_page', | |
| 'fields': [ | |
| {'name': 'titulo', 'selector': 'h1', 'type': 'text'}, | |
| ], | |
| }) | |
| print(f'Scrape: {resp.operation_id} | {resp.status} | {resp.total_found} items') | |
| # Email delivery | |
| deliver = client.deliver_results(resp.operation_id, emails=['tu@email.com']) | |
| print(f'Email enviado: {deliver[\"email_sent\"]}') | |
| client.close() | |
| " | |
| ``` | |
| --- | |
| ## βοΈ Stack instalado | |
| | Paquete | Estado | | |
| |---------|--------| | |
| | Python 3.12.1 | β | | |
| | FastAPI 0.136.1 | β | | |
| | httpx 0.28.1 | β | | |
| | uvicorn 0.46.0 | β | | |
| | PySide6-Essentials 6.11.1 | β | | |
| | pytest 9.0.3 | β | | |
| | beautifulsoup4 4.14.3 | β | | |
| | lxml 6.1.0 | β | | |
| | pydantic 2.13.3 | β | | |
| | python-dotenv 1.2.2 | β | | |
| --- | |
| ## π Archivos clave | |
| ``` | |
| modulo_1_servicio/ | |
| main.py β Entry point FastAPI | |
| api/routes_scrape.py β Endpoints /api/scrape y /api/results | |
| api/routes_deliver.py β Endpoints /api/deliver | |
| deliveries/email_sender.py β EmailDelivery con soporte .env | |
| scraping/engine.py β Orchestrator + FilterEngine | |
| scraping/extractors/ β BaseExtractor + BeautifulSoupExtractor | |
| scraping/url_utils.py β normalize_url() (Fase 1) | |
| scraping/anti_scraping.py β UARotator, RetryPolicy, DomainDelay (Fase 1) | |
| scraping/adapters/models.py β SiteAdapter, AdapterField (Pydantic) | |
| scraping/adapters/loader.py β AdapterLoader (carga YAML) | |
| modulo_2_admin/ | |
| core/client.py β ScrapperClient (HTTP) | |
| core/models.py β ScrapeJobConfig, FieldConfig, etc. | |
| core/repository.py β LocalRepository (SQLite) | |
| ui/main.py β PythonBridge + entry point PySide6 | |
| ui/qml/main.qml β UI completa (Pane-based, sin padding en Rectangles) | |
| tests/ | |
| modulo_2/test_integration.py β 8 tests de integraciΓ³n admin β scraper | |
| modulo_1/ β 88 tests del servicio | |
| test_url_utils.py β 9 tests para normalize_url | |
| test_anti_scraping.py β 14 tests para UARotator/RetryPolicy/DomainDelay | |
| test_adapter_loader.py β 9 tests para AdapterLoader | |
| adapters/ β Adaptadores YAML (ej: example_httpbin.yaml) | |
| .env β Credenciales SMTP (no comitear) | |
| .env.example β Template de configuraciΓ³n | |
| CHECKPOINT.md β Este archivo | |
| ``` | |
| --- | |
| --- | |
| ## ποΈ VisiΓ³n ArquitectΓ³nica β Sistema GenΓ©rico de BΓΊsqueda | |
| ### Arquitectura en capas | |
| ``` | |
| USUARIO: "autos usados Mexico < 10000" | |
| β | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββ | |
| β INTERPRETE DE CONSULTAS β π | |
| β Extrae: vertical=cars, β | |
| β pais=mexico, max_price=10000 β | |
| ββββββββββββββββ¬βββββββββββββββββββ | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββ | |
| β BUSCADOR DE PLANTILLAS β π | |
| β Encuentra adaptadores para β | |
| β "cars" en sitios conocidos β | |
| ββββββββββββββββ¬βββββββββββββββββββ | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββ | |
| β ADAPTADOR DE SITIO (YAML) β π | |
| β Traduce consulta β URL β | |
| β Conoce selectores, paginaciΓ³n β | |
| ββββββββββββββββ¬βββββββββββββββββββ | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββ | |
| β MOTOR DE SCRAPING β β EXISTE | |
| ββββββββββββββββ¬βββββββββββββββββββ | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββ | |
| β NORMALIZADOR DE RESULTADOS β π | |
| β Unifica datos de mΓΊltiples β | |
| β fuentes en schema comΓΊn β | |
| ββββββββββββββββ¬βββββββββββββββββββ | |
| βΌ | |
| βββββββββββββββββββββββββββββββββββ | |
| β ENTREGA (Web/Email/WA) β β EXISTE | |
| βββββββββββββββββββββββββββββββββββ | |
| ``` | |
| ### Plan de implementaciΓ³n | |
| | Fase | QuΓ© incluye | Estado | | |
| |------|------------|--------| | |
| | **Fase 1** β Base sΓ³lida | URL normalizer, adaptadores YAML, anti-scraping, endpoint, tests | β **Completada** | | |
| | **Fase 2** β Biblioteca | Adaptadores para sitios comunes, schema canΓ³nico | β³ Siguiente | | |
| | **Fase 3** β IntΓ©rprete | Parseo de consultas, buscador de plantillas | β³ | | |
| | **Fase 4** β GUI | NavegaciΓ³n por verticales, bΓΊsqueda guiada | β³ | | |
| --- | |
| ## π§ Pendiente para prΓ³xima sesiΓ³n | |
| - [ ] **Fase 2**: Biblioteca de adaptadores para sitios comunes (ML, OLX, etc.) | |
| - [ ] **Fase 2**: Schema canΓ³nico de resultados | |
| - [ ] **Fase 2**: Normalizador de datos multi-fuente | |
| - [ ] **Fase 3**: IntΓ©rprete de consultas en lenguaje natural | |