novasearch / CHECKPOINT.md
Randy Mustelier Rivero
feat: completar Fase 1 - URL normalizer, adapters YAML, anti-scraping, endpoint y 36 tests
e597ad1
|
Raw History Blame Contribute Delete
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