Skip to content

Commit

Permalink
Extract URLs to own module
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Aug 27, 2024
1 parent 2790edd commit 2dc7e78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
13 changes: 5 additions & 8 deletions icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import icepyx.core.APIformatting as apifmt
from icepyx.core.auth import EarthdataAuthMixin
import icepyx.core.exceptions
from icepyx.core.urls import DOWNLOAD_BASE_URL, ORDER_BASE_URL, GRANULE_SEARCH_BASE_URL


def info(grans):
Expand Down Expand Up @@ -201,8 +202,6 @@ def get_avail(self, CMRparams, reqparams, cloud=False):
# if not hasattr(self, 'avail'):
self.avail = []

granule_search_url = "https://cmr.earthdata.nasa.gov/search/granules"

headers = {"Accept": "application/json", "Client-Id": "icepyx"}
# note we should also check for errors whenever we ping NSIDC-API -
# make a function to check for errors
Expand All @@ -220,7 +219,7 @@ def get_avail(self, CMRparams, reqparams, cloud=False):
headers["CMR-Search-After"] = cmr_search_after

response = requests.get(
granule_search_url,
GRANULE_SEARCH_BASE_URL,
headers=headers,
params=apifmt.to_string(params),
)
Expand Down Expand Up @@ -308,8 +307,6 @@ def place_order(
query.Query.order_granules
"""

base_url = "https://n5eil02u.ecs.nsidc.org/egi/request"

self.get_avail(CMRparams, reqparams)

if subset is False:
Expand Down Expand Up @@ -345,7 +342,7 @@ def place_order(
)
request_params.update({"page_num": page_num})

request = self.session.get(base_url, params=request_params)
request = self.session.get(ORDER_BASE_URL, params=request_params)

Check warning on line 345 in icepyx/core/granules.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/granules.py#L345

Added line #L345 was not covered by tests

# DevGoal: use the request response/number to do some error handling/
# give the user better messaging for failures
Expand Down Expand Up @@ -377,7 +374,7 @@ def place_order(
print("order ID: ", orderID)

# Create status URL
statusURL = base_url + "/" + orderID
statusURL = f"{ORDER_BASE_URL}/{orderID}"

Check warning on line 377 in icepyx/core/granules.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/granules.py#L377

Added line #L377 was not covered by tests
if verbose is True:
print("status URL: ", statusURL)

Expand Down Expand Up @@ -522,7 +519,7 @@ def download(self, verbose, path, restart=False):
i_order = self.orderIDs.index(order_start) + 1

for order in self.orderIDs[i_order:]:
downloadURL = "https://n5eil02u.ecs.nsidc.org/esir/" + order + ".zip"
downloadURL = f"{DOWNLOAD_BASE_URL}/{order}.zip"

Check warning on line 522 in icepyx/core/granules.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/granules.py#L522

Added line #L522 was not covered by tests
# DevGoal: get the download_url from the granules

if verbose is True:
Expand Down
9 changes: 4 additions & 5 deletions icepyx/core/is2ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import earthaccess

from icepyx.core.urls import COLLECTION_SEARCH_BASE_URL, EGI_BASE_URL


# ICESat-2 specific reference functions

Expand Down Expand Up @@ -82,8 +84,7 @@ def about_product(prod):
query.Query.product_all_info
"""

cmr_collections_url = "https://cmr.earthdata.nasa.gov/search/collections.json"
response = requests.get(cmr_collections_url, params={"short_name": prod})
response = requests.get(COLLECTION_SEARCH_BASE_URL, params={"short_name": prod})
results = json.loads(response.content)
return results

Expand All @@ -101,9 +102,7 @@ def _get_custom_options(session, product, version):
"Don't forget to log in to Earthdata using query.earthdata_login()"
)

capability_url = (
f"https://n5eil02u.ecs.nsidc.org/egi/capabilities/{product}.{version}.xml"
)
capability_url = f"{EGI_BASE_URL}/capabilities/{product}.{version}.xml"

Check warning on line 105 in icepyx/core/is2ref.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/is2ref.py#L105

Added line #L105 was not covered by tests
response = session.get(capability_url)
root = ET.fromstring(response.content)

Expand Down
10 changes: 10 additions & 0 deletions icepyx/core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Final

CMR_BASE_URL: Final = "https://cmr.earthdata.nasa.gov"
GRANULE_SEARCH_BASE_URL: Final = f"{CMR_BASE_URL}/search/granules"
COLLECTION_SEARCH_BASE_URL: Final = f"{CMR_BASE_URL}/search/collections.json"

EGI_BASE_URL: Final = "https://n5eil02u.ecs.nsidc.org/egi"
ORDER_BASE_URL: Final = f"{EGI_BASE_URL}/request"

DOWNLOAD_BASE_URL: Final = "https://n5eil02u.ecs.nsidc.org/esir"

0 comments on commit 2dc7e78

Please sign in to comment.