mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-12 03:41:19 +00:00
Use get_data helper when executing searches
This commit is contained in:
parent
e1a8c4d260
commit
2ab913018d
1 changed files with 3 additions and 13 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue