Skip to content

Commit da0d48b

Browse files
committed
cache looks for any .tif files
1 parent 34f0be5 commit da0d48b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

earthpy/api/appeears.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def __init__(
119119
if ea_dir is None:
120120
ea_dir = os.path.join(pathlib.Path.home(), 'earth-analytics')
121121
self.data_dir = os.path.join(ea_dir, download_key)
122+
os.makedirs(self.data_dir, exist_ok=True)
122123

123124
def appeears_request(
124125
self, endpoint,
@@ -298,6 +299,15 @@ def download_files(self, cache=True):
298299
cache : bool
299300
Use cache to avoid repeat downloads
300301
"""
302+
if cache:
303+
existing_files = glob(os.path.join(self.data_dir, '*' '*.tif'))
304+
if existing_files:
305+
logging.info(
306+
'Files already exist in {}. '
307+
'Set cache=False to overwrite.'.format(self.data_dir))
308+
return
309+
310+
# Check task status
301311
status = self.task_status
302312
logging.info('Current task status: {}'.format(status))
303313

@@ -321,8 +331,6 @@ def download_files(self, cache=True):
321331

322332
# Create a destination directory to store the file in
323333
filepath = os.path.join(self.data_dir, file_info['file_name'])
324-
if not os.path.exists(os.path.dirname(filepath)):
325-
os.makedirs(os.path.dirname(filepath))
326334

327335
# Write the file to the destination directory
328336
if os.path.exists(filepath) and cache:

0 commit comments

Comments
 (0)