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 26, 2024
1 parent 3b70eea commit fadcb29
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 @@ -10,14 +10,14 @@
import os
import pprint
import zipfile
from typing import Final
from requests.compat import unquote
from xml.etree import ElementTree as ET

import icepyx.core.APIformatting as apifmt
import icepyx.core.exceptions
from icepyx.core.auth import EarthdataAuthMixin
from icepyx.core.types import CMRParams, EGISpecificParams
from icepyx.core.urls import DOWNLOAD_BASE_URL, ORDER_BASE_URL, GRANULE_SEARCH_BASE_URL


def info(grans):
Expand Down Expand Up @@ -211,8 +211,6 @@ def get_avail(
# if not hasattr(self, 'avail'):
self.avail = []

granule_search_url: Final = "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 @@ -230,7 +228,7 @@ def get_avail(
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 @@ -317,7 +315,6 @@ def place_order(
--------
query.Query.order_granules
"""
base_url: Final = "https://n5eil02u.ecs.nsidc.org/egi/request"

self.get_avail(CMRparams, reqparams)

Expand Down Expand Up @@ -354,7 +351,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 354 in icepyx/core/granules.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/granules.py#L354

Added line #L354 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 @@ -386,7 +383,7 @@ def place_order(
print("order ID: ", orderID)

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

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

View check run for this annotation

Codecov / codecov/patch

icepyx/core/granules.py#L386

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

Expand Down Expand Up @@ -539,7 +536,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 539 in icepyx/core/granules.py

View check run for this annotation

Codecov / codecov/patch

icepyx/core/granules.py#L539

Added line #L539 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 fadcb29

Please sign in to comment.