Skip to content

Commit

Permalink
feat: add download method to dataprocessor class
Browse files Browse the repository at this point in the history
  • Loading branch information
HAEKADI committed Nov 27, 2024
1 parent 5bb0199 commit f1c3e02
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions helpers/data_processor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import ABC, abstractmethod
import logging
import requests
from dag_datalake_sirene.helpers.minio_helpers import minio_client, File
from dag_datalake_sirene.helpers.tchap import send_message
from dag_datalake_sirene.helpers.utils import fetch_and_store_last_modified_metadata
Expand All @@ -17,6 +18,26 @@ def __init__(self, config: DataSourceConfig):
self.config = config
self.minio_client = minio_client

def download_data(self, destination):
"""
Downloads data from the specified URL and saves it to the destination path.
Args:
url (str): The URL to download data from.
destination (str): The file path where the downloaded data will be saved.
"""
try:
r = requests.get(self.config.url)
r.raise_for_status()
with open(destination, "wb") as f:
for chunk in r.iter_content(1024):
f.write(chunk)
logging.info(
f"Data downloaded successfully from {self.config.url} to {destination}."
)
except requests.exceptions.RequestException as e:
logging.error(f"Error downloading data from {self.config.url}: {e}")

@abstractmethod
def preprocess_data(self):
"""
Expand Down

0 comments on commit f1c3e02

Please sign in to comment.