Use get_data helper when executing searches

This commit is contained in:
Mouse Reeve 2021-03-13 08:52:36 -08:00
parent e1a8c4d260
commit 2ab913018d

View file

@ -44,21 +44,10 @@ class AbstractMinimalConnector(ABC):
if min_confidence: if min_confidence:
params["min_confidence"] = min_confidence params["min_confidence"] = min_confidence
resp = requests.get( data = get_data(
"%s%s" % (self.search_url, query), "%s%s" % (self.search_url, query),
params=params, params=params,
headers={
"Accept": "application/json; charset=utf-8",
"User-Agent": settings.USER_AGENT,
},
) )
if not resp.ok:
resp.raise_for_status()
try:
data = resp.json()
except ValueError as e:
logger.exception(e)
raise ConnectorException("Unable to parse json response", e)
results = [] results = []
for doc in self.parse_search_data(data)[:10]: for doc in self.parse_search_data(data)[:10]:
@ -234,11 +223,12 @@ def dict_from_mappings(data, mappings):
return result return result
def get_data(url): def get_data(url, params=None):
""" wrapper for request.get """ """ wrapper for request.get """
try: try:
resp = requests.get( resp = requests.get(
url, url,
params=params,
headers={ headers={
"Accept": "application/json; charset=utf-8", "Accept": "application/json; charset=utf-8",
"User-Agent": settings.USER_AGENT, "User-Agent": settings.USER_AGENT,