# Path: src/tsgettoolbox/ulmo/util/misc.py
# def download_if_new(url, path, check_modified=True):
#     """downloads the file located at `url` to `path`, if check_modified is True
#     it will only download if the url's last-modified header has a more recent
#     date than the filesystem's last modified date for the file
#     """
#     parsed = urllib.parse.urlparse(url)
# 
#     if os.path.exists(path) and not check_modified:
#         return
# 
#     if parsed.scheme.startswith("ftp"):
#         _ftp_download_if_new(url, path, check_modified)
#     elif parsed.scheme.startswith("http"):
#         _http_download_if_new(url, path, check_modified)
#     else:
#         raise NotImplementedError("only ftp and http urls are currently implemented")
# 
# def mkdir_if_doesnt_exist(dir_path):
#     """makes a directory if it doesn't exist"""
#     if not os.path.exists(dir_path):
#         os.makedirs(dir_path)


import hashlib
import os
import zipfile
    import subprocess
    import rasterio
from .misc import download_if_new, mkdir_if_doesnt_exist
    from pyproj import Proj
    print(
        subprocess.check_output(
            [
                "gdalwarp",
                "-overwrite",
                "-te",
                repr(xmin),
                repr(ymin),
                repr(xmax),
                repr(ymax),
                output_vrt,
                output_path,
            ]
        )
    )
    print("Output raster saved at %s", output_path)


def download_tiles(path, tile_urls, tile_fmt, check_modified=False):
    raster_tiles = []

    if isinstance(tile_urls, str):
        tile_urls = [tile_urls]

    for i, url in enumerate(tile_urls):
        filename = os.path.split(url)[-1]
        print(
            "... downloading tile {} of {} from {}".format(i + 1, len(tile_urls), url)
        )
        mkdir_if_doesnt_exist(path)

# Path: src/tsgettoolbox/ulmo/util/misc.py
# def download_if_new(url, path, check_modified=True):
#     """downloads the file located at `url` to `path`, if check_modified is True
#     it will only download if the url's last-modified header has a more recent
#     date than the filesystem's last modified date for the file
#     """
#     parsed = urllib.parse.urlparse(url)
# 
#     if os.path.exists(path) and not check_modified:
#         return
# 
#     if parsed.scheme.startswith("ftp"):
#         _ftp_download_if_new(url, path, check_modified)
#     elif parsed.scheme.startswith("http"):
#         _http_download_if_new(url, path, check_modified)
#     else:
#         raise NotImplementedError("only ftp and http urls are currently implemented")
# 
# def mkdir_if_doesnt_exist(dir_path):
#     """makes a directory if it doesn't exist"""
#     if not os.path.exists(dir_path):
#         os.makedirs(dir_path)


# Path: src/tsgettoolbox/ulmo/util/raster.py
import hashlib
import os
import zipfile
    import subprocess
    import rasterio
from .misc import download_if_new, mkdir_if_doesnt_exist
    from pyproj import Proj

    print(
        subprocess.check_output(
            [
                "gdalwarp",
                "-overwrite",
                "-te",
                repr(xmin),
                repr(ymin),
                repr(xmax),
                repr(ymax),
                output_vrt,
                output_path,
            ]
        )
    )
    print("Output raster saved at %s", output_path)


def download_tiles(path, tile_urls, tile_fmt, check_modified=False):
    raster_tiles = []

    if isinstance(tile_urls, str):
        tile_urls = [tile_urls]

    for i, url in enumerate(tile_urls):
        filename = os.path.split(url)[-1]
        print(
            "... downloading tile {} of {} from {}".format(i + 1, len(tile_urls), url)
        )
        mkdir_if_doesnt_exist(path)

        mkdir_if_doesnt_exist(os.path.join(path, "zip"))