58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""DAG diario – ArgenProp AR (Argentina)
|
||
Scraper SSR basado en sitemaps geográficos de argenprop.com
|
||
"""
|
||
from datetime import datetime, timedelta
|
||
import paramiko
|
||
|
||
from airflow import DAG
|
||
from airflow.operators.python import PythonOperator
|
||
|
||
VPS_HOST = '152.53.242.31'
|
||
VPS_USER = 'root'
|
||
VPS_KEY = '/opt/airflow/config/.ssh/id_rsa'
|
||
|
||
SCRAPER_CMD = (
|
||
'ARGENPROP_DAILY=1 '
|
||
'timeout 14400 '
|
||
'/home/jpuma/proyectos/bot-sunat/.venv/bin/python '
|
||
'/opt/scrapers/argenprop_ar/scraper.py 2>&1'
|
||
)
|
||
|
||
def run_scraper(**ctx):
|
||
client = paramiko.SSHClient()
|
||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
client.connect(VPS_HOST, username=VPS_USER, key_filename=VPS_KEY, timeout=30)
|
||
_, stdout, stderr = client.exec_command(SCRAPER_CMD, timeout=14400)
|
||
output = stdout.read().decode('utf-8', errors='replace')
|
||
err = stderr.read().decode('utf-8', errors='replace')
|
||
client.close()
|
||
print(output[-4000:] if len(output) > 4000 else output)
|
||
if err:
|
||
print('STDERR:', err[-1000:])
|
||
if 'Finalizado:' not in output:
|
||
raise RuntimeError('Scraper no imprimió "Finalizado:" — posible error')
|
||
return output.split('Finalizado:')[-1].strip()
|
||
|
||
|
||
default_args = {
|
||
'owner': 'jpuma',
|
||
'retries': 0,
|
||
'retry_delay': timedelta(minutes=10),
|
||
'execution_timeout': timedelta(hours=5),
|
||
}
|
||
|
||
with DAG(
|
||
dag_id='argenprop_ar_daily',
|
||
default_args=default_args,
|
||
description='Scraper diario ArgenProp AR (SSR sitemap)',
|
||
schedule_interval='0 4 * * *',
|
||
start_date=datetime(2026, 8, 1),
|
||
catchup=False,
|
||
max_active_runs=1,
|
||
tags=['argentina', 'daily', 'inmuebles'],
|
||
) as dag:
|
||
PythonOperator(
|
||
task_id='scrape_argenprop_ar',
|
||
python_callable=run_scraper,
|
||
)
|