diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2020-12-15 02:56:27 +0100 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2020-12-15 02:56:27 +0100 |
commit | 024694edb909eeb047115ab62a52df6786f931c0 (patch) | |
tree | 99e8613f996bbe276bf7601c2abebc9cb4d09d0f /fuzzycat/utils.py | |
parent | b9b2aafe08abc7f131514a2eba804a569d424efb (diff) | |
download | fuzzycat-024694edb909eeb047115ab62a52df6786f931c0.tar.gz fuzzycat-024694edb909eeb047115ab62a52df6786f931c0.zip |
fix cmdline tool
Diffstat (limited to 'fuzzycat/utils.py')
-rw-r--r-- | fuzzycat/utils.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/fuzzycat/utils.py b/fuzzycat/utils.py index 9aa3a4c..1cdac47 100644 --- a/fuzzycat/utils.py +++ b/fuzzycat/utils.py @@ -159,17 +159,15 @@ def random_word(func=lambda w: True, wordsfile='/usr/share/dict/words'): def random_idents_from_query(query="*", es="https://search.fatcat.wiki/fatcat_release/_search", - max_retries=10, r=2): """ Return a number of random idents from a search query. """ - for _ in range(max_retries): - resp = requests.get(es, params={"q": query}) - if resp.status_code != 200: - raise RuntimeError('could not query {} for random item: {}'.format(es, r.url)) - payload = resp.json() - if payload["hits"]["total"] < 2: - continue - idents = [doc["_source"]["ident"] for doc in payload["hits"]["hits"]] - return random.sample(idents, r) + resp = requests.get(es, params={"q": query}) + if resp.status_code != 200: + raise RuntimeError('could not query {} for random item: {}'.format(es, r.url)) + payload = resp.json() + if payload["hits"]["total"] < 2: + raise RuntimeError('to few documents') + idents = [doc["_source"]["ident"] for doc in payload["hits"]["hits"]] + return random.sample(idents, r) |