Está apresentando o seguinte erro ao abrir o airflow:
Broken DAG: [/home/poletto/Documents/airflowalura/dags/dados_climaticos.py] Traceback (most recent call last):
File "/home/poletto/Documents/airflowalura/venv/lib/python3.9/site-packages/airflow/models/baseoperator.py", line 390, in apply_defaults
result = func(self, **kwargs, default_args=default_args)
File "/home/poletto/Documents/airflowalura/venv/lib/python3.9/site-packages/airflow/operators/python.py", line 158, in init
raise AirflowException('python_callable
param must be callable')
airflow.exceptions.AirflowException: python_callable
param must be callable
Segue meu código:
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
from airflow.macros import ds_add
import pendulum
from os.path import join
import pandas as pd
with DAG(
"dados_climaticos",
start_date=pendulum.datetime(2022, 8, 22, tz="UTC"),
schedule_interval='0 0 * * 1', # executar toda segunda feira
) as dag:
tarefa_1 = BashOperator(
task_id = 'cria_pasta',
bash_command = 'mkdir -p "/home/poletto/Documents/airflowalura/semana={{data_interval_end.strftime("%Y-%m-%d")}}"'
)
def extrai_dados(data_interval_end):
city = 'Boston'
key = 'MV6BM7W839MLNR6AWGC3QSMPJ'
URL = join('https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/',
f'{city}/{data_interval_end}/{ds_add(data_interval_end, 7)}?unitGroup=metric&include=days&key={key}&contentType=csv')
dados = pd.read_csv(URL)
file_path = f'/home/poletto/Documents/airflowalura/semana={data_interval_end}/'
dados.to_csv(file_path + 'dados_brutos.csv')
dados[['datetime', 'tempmin', 'temp', 'tempmax']].to_csv(file_path + 'temperaturas.csv')
dados[['datetime', 'description', 'icon']].to_csv(file_path + 'condicoes.csv')
tarefa_2 = PythonOperator(
task_id = 'extrai_dados',
python_callable = 'extrai_dados',
op_kwargs = {'data_interval_end': '{{data_interval_end.strftime("%Y-%m-%d")}}'}
)
tarefa_1 >> tarefa_2