Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add file download functinality to ERDDAP #330

Merged
merged 7 commits into from
Jan 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions erddapy/erddapy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Pythonic way to access ERDDAP data."""

import functools
import hashlib
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union
from urllib.parse import urlparse
from urllib.request import urlretrieve

import pandas as pd
Expand Down Expand Up @@ -481,5 +481,8 @@ def download_file(
):
"""Download the dataset to a file in a user specified format"""
url = self.get_download_url(response=file_type)
fname = Path(Path(urlparse(url).path).name)
urlretrieve(url, fname)
constraints_str = str(self.constraints) + str(self.variables)
callumrollo marked this conversation as resolved.
Show resolved Hide resolved
constraints_hash = hashlib.sha1(constraints_str.encode("UTF-8")).hexdigest()
callumrollo marked this conversation as resolved.
Show resolved Hide resolved
file_name = Path(f"{self.dataset_id}_{constraints_hash}.{file_type}")
callumrollo marked this conversation as resolved.
Show resolved Hide resolved
if not file_name.exists():
urlretrieve(url, file_name)
Loading