From fb97825b982e5ae8fc89196d857dfaac2b6c9dd7 Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Sun, 22 Sep 2019 13:32:26 -0400 Subject: [PATCH] Add limit to similarity of search result --- src/utils/scraper.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index 702bb50..28532e1 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -27,9 +27,9 @@ async def get_post(url): ident = re.search('#(\\d+)', post['delreason']).group(1) post = await u.fetch('http://e621.net/post/show.json', params={'id': ident}, json=True) source = f'https://e621.net/post/show/{post["id"]}' - similarity = re.search('\\d+', soup.find(string=re.compile('similarity'))).group(0) + '% Match' + similarity = re.search('\\d+', soup.find(string=re.compile('similarity'))).group(0) - return post, source, similarity + return post, source, similarity + '% Match' else: raise IndexError @@ -53,9 +53,10 @@ async def get_post(url): 'artist': [result['data'][artist]], 'score': 'SauceNAO'} source = result['data']['ext_urls'][0] - similarity = re.search('(\\d+)\\.', result['header']['similarity']).group(1) + '% Match' + similarity = re.search('(\\d+)\\.', result['header']['similarity']).group(1) - return post, source, similarity + if int(similarity) >= 55: + return post, source, similarity + '% Match' raise exc.MatchError(re.search('\\/([^\\/]+)$', url).group(1))