Skip to content

Commit

Permalink
feat: option to use constraints file url
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahovnik committed Sep 14, 2023
1 parent 13ef3d9 commit e6f453b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 119 deletions.
17 changes: 13 additions & 4 deletions eodag/api/product/request_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import re

import requests

from eodag.utils.exceptions import MisconfiguredError


Expand Down Expand Up @@ -49,13 +51,20 @@ class RequestSplitter:
def __init__(self, config):
self.config = config.__dict__
if (
"constraints_file_path" not in self.config
or not self.config["constraints_file_path"]
"constraints_file_path" in self.config
and self.config["constraints_file_path"]
):
self.constraints = {}
else:
with open(self.config["constraints_file_path"]) as f:
self.constraints = json.load(f)
elif (
"constraints_file_url" in self.config
and self.config["constraints_file_url"]
):
res = requests.get(self.config["constraints_file_url"])
self.constraints = res.json()
else:
self.constraints = {}

self.metadata = self.config["metadata_mapping"]
if "multi_select_values" in self.config:
self.multi_select_values = self.config["multi_select_values"]
Expand Down
10 changes: 10 additions & 0 deletions eodag/plugins/apis/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def query(
]["constraints_file_path"]
else:
self.config.constraints_file_path = ""
if (
kwargs["productType"] in getattr(self.config, "products", {})
and "constraints_file_url"
in getattr(self.config, "products", {})[kwargs["productType"]]
):
self.config.constraints_file_url = getattr(self.config, "products", {})[
kwargs["productType"]
]["constraints_file_url"]
else:
self.config.constraints_file_url = ""
# start date
if "startTimeFromAscendingNode" not in kwargs and "id" not in kwargs:
kwargs["startTimeFromAscendingNode"] = (
Expand Down
10 changes: 10 additions & 0 deletions eodag/plugins/apis/ecmwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def query(
]["constraints_file_path"]
else:
self.config.constraints_file_path = ""
if (
product_type in getattr(self.config, "products", {})
and "constraints_file_url"
in getattr(self.config, "products", {})[product_type]
):
self.config.constraints_file_url = getattr(self.config, "products", {})[
product_type
]["constraints_file_url"]
else:
self.config.constraints_file_url = ""

# start date
if "startTimeFromAscendingNode" not in kwargs and "id" not in kwargs:
Expand Down
Loading

0 comments on commit e6f453b

Please sign in to comment.