-
Notifications
You must be signed in to change notification settings - Fork 0
/
climate_data
42 lines (33 loc) · 1.5 KB
/
climate_data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
from datetime import datetime
with DAG(
"dados_climaticos",
start_date=pendulum.datetime(2023, 1, 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/antonio/Documents/airflowalura/semana={{data_interval_end.strftime("%Y-%m-%d")}}"'
)
def extrai_dados(data_interval_end):
city = 'Boston'
key = 'ANZQ5K8QQP8BXZ85F4ZEQ2FPK'
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/antonio/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}}'}
)
tarefa_1 >> tarefa_2