aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fuzzycat/__main__.py2
-rw-r--r--fuzzycat/utils.py11
2 files changed, 7 insertions, 6 deletions
diff --git a/fuzzycat/__main__.py b/fuzzycat/__main__.py
index 89e3a12..8ff20f5 100644
--- a/fuzzycat/__main__.py
+++ b/fuzzycat/__main__.py
@@ -26,7 +26,7 @@ import requests
from fuzzycat.cluster import (Cluster, release_key_title, release_key_title_ngram,
release_key_title_normalized, release_key_title_nysiis,
release_key_title_sandcrawler)
-from fuzzycat.utils import random_word
+from fuzzycat.utils import random_idents_from_query, random_word
from fuzzycat.verify import GroupVerifier, verify
logging.getLogger("requests").setLevel(logging.WARNING)
diff --git a/fuzzycat/utils.py b/fuzzycat/utils.py
index cf74220..9aa3a4c 100644
--- a/fuzzycat/utils.py
+++ b/fuzzycat/utils.py
@@ -6,6 +6,7 @@ import random
import re
import string
+import requests
from glom import PathAccessError, glom
printable_no_punct = string.digits + string.ascii_letters + string.whitespace
@@ -164,11 +165,11 @@ def random_idents_from_query(query="*",
Return a number of random idents from a search query.
"""
for _ in range(max_retries):
- r = requests.get(es, params={"q": query})
- if r.status_code != 200:
+ resp = requests.get(es, params={"q": query})
+ if resp.status_code != 200:
raise RuntimeError('could not query {} for random item: {}'.format(es, r.url))
- resp = r.json()
- if resp["hits"]["total"] < 2:
+ payload = resp.json()
+ if payload["hits"]["total"] < 2:
continue
- idents = [doc["_source"]["ident"] for doc in resp["hits"]["hits"]]
+ idents = [doc["_source"]["ident"] for doc in payload["hits"]["hits"]]
return random.sample(idents, r)