Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions modelmw_client/model_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,17 @@ def send(self, request, **kwargs):

self.mmw_session.headers.update(
{
"Host": "staging.modelmywatershed.org",
# "Host": "staging.modelmywatershed.org",
"Authorization": "Token " + self.api_key,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0",
"Accept": "*/*",
"Connection": "keep-alive",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.5",
"DNT": "1",
"Upgrade-Insecure-Requests": "1",
"Origin": "https://staging.modelmywatershed.org",
"Referer": "{}/".format(self.mmw_host),
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0",
# "Accept": "*/*",
# "Connection": "keep-alive",
# "Accept-Encoding": "gzip, deflate, br",
# "Accept-Language": "en-US,en;q=0.5",
# "DNT": "1",
# "Upgrade-Insecure-Requests": "1",
# "Origin": "https://staging.modelmywatershed.org",
# "Referer": "{}/".format(self.mmw_host),
}
)

Expand Down Expand Up @@ -316,9 +316,9 @@ def login(self, mmw_user: str, mmw_pass: str) -> bool:
"Cache-Control": "no-cache",
},
)
self.mmw_session.headers.update(
{"X-CSRFToken": self.mmw_session.cookies["csrftoken"]}
)
# self.mmw_session.headers.update(
# {"X-CSRFToken": self.mmw_session.cookies["csrftoken"]}
# )
except Exception as ex:
self.api_logger.warn("Failed to log in: {}".format(ex))
return False
Expand All @@ -332,27 +332,27 @@ def _set_request_headers(self, request_endpoint: str) -> None:
Args:
request_endpoint (str): The endpoint for the request
"""

if self.project_endpoint in request_endpoint:
headers = {
"Content-Type": "application/json",
"Referer": "https://staging.modelmywatershed.org/project/",
"X-Requested-With": "XMLHttpRequest",
}
elif self.old_modeling_endpoint in request_endpoint:
headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Referer": "https://staging.modelmywatershed.org/project/",
"X-Requested-With": "XMLHttpRequest",
}
else:
headers = {
"Content-Type": "application/json",
"Referer": "https://staging.modelmywatershed.org/analyze",
"X-Requested-With": "XMLHttpRequest",
}

self.mmw_session.headers.update(headers)
pass
# if self.project_endpoint in request_endpoint:
# headers = {
# "Content-Type": "application/json",
# "Referer": "https://staging.modelmywatershed.org/project/",
# "X-Requested-With": "XMLHttpRequest",
# }
# elif self.old_modeling_endpoint in request_endpoint:
# headers = {
# "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
# "Referer": "https://staging.modelmywatershed.org/project/",
# "X-Requested-With": "XMLHttpRequest",
# }
# else:
# headers = {
# "Content-Type": "application/json",
# "Referer": "https://staging.modelmywatershed.org/analyze",
# "X-Requested-With": "XMLHttpRequest",
# }

# self.mmw_session.headers.update(headers)

def _pprint_endpoint(self, request_endpoint: str) -> None:
"""Prints out the request endpoint in a format usable for a Windows endpoint
Expand Down Expand Up @@ -1075,8 +1075,8 @@ def run_batch_gwlfe(
# Internally, the ModelMW site uses the inputmod_hash in scenerios to
# determine whether it can use cached results or if it needs to
# re-run the job
"inputmod_hash": self.inputmod_hash,
"modifications": land_use_modification_set,
# "inputmod_hash": self.inputmod_hash,
# "modifications": land_use_modification_set,
"job_uuid": mapshed_job_id,
}
gwlfe_job_dict = self.run_mmw_job(
Expand Down Expand Up @@ -1111,7 +1111,7 @@ def run_batch_gwlfe(
gwlfe_summaries.append(gwlfe_summary)

# join various result
if len(gwlfe_metas) < 0:
if len(gwlfe_metas) > 0:
gwlfe_results = {}
gwlfe_results["gwlfe_monthly"] = pd.concat(
gwlfe_monthlies, ignore_index=True
Expand Down Expand Up @@ -1447,3 +1447,5 @@ def dump_job_json(self, job_dict: ModelMyWatershedJob) -> None:
"w",
) as fp:
json.dump(job_dict, fp, indent=2)

# %%