Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sj_search = get_url(decode_base64("aHR0cHM6Ly9zZXJpZW5qdW5raWVzLm9yZy9zZXJpZS9zZWFyY2g/cT0=") + sj_query,
configfile, dbfile, scraper)
try:
sj_results = BeautifulSoup(sj_search, 'lxml').findAll("a", href=re.compile("/serie"))
except:
sj_results = []
if special:
append = " (" + special + ")"
else:
append = ""
i = 0
results = {}
for result in sj_results:
r_title = result.text
r_rating = fuzz.ratio(title.lower(), r_title)
if r_rating > 40:
res = {"payload": encode_base64(result['href'] + "|" + r_title + "|" + str(special)),
"title": r_title + append}
results["result" + str(i + 1000)] = res
i += 1
sj_final = results
return bl_final, sj_final
def get_combined_fuzz_score(self, a, b, mode='geom_mean'):
a, b = clean_name(a), clean_name(b)
simple = float(fuzz.ratio(a, b) * self.weight['simple'])
partial = float(fuzz.partial_ratio(a, b) * self.weight['partial'])
return self.combine_scores(simple, partial, mode=mode)
def put_title(self, text, level):
text = text.strip()
if not fuzz.ratio(text, g.last_title.get(level, ''), score_cutoff=92):
self.ofile.write('#'*level + ' ' + text + '\n\n')
g.last_title[level] = text
continue
try:
#if self.DEBUG:
#print("")
#print("___" + current_thing_title)
probable_thing_title_confidence = 100
if target_thing_title == None: # If no thing title provided, we go over every thing and let the property be leading in finding a match.
pass
elif target_thing_title == current_thing_title: # If the thing title is a perfect match
probable_thing_title = current_thing_title
if self.DEBUG:
print("FOUND THE CORRECT THING: " + str(current_thing_title))
elif fuzz.ratio(str(target_thing_title), current_thing_title) > 85: # If the title is a fuzzy match
if self.DEBUG:
print("This thing title is pretty similar, so it could be what we're looking for: " + str(current_thing_title))
probable_thing_title = current_thing_title
probable_thing_title_confidence = 85
elif target_space != None:
space_title = str(target_space) + " " + str(target_thing_title)
#if self.DEBUG:
# print("space title = " + str(target_space) + " + " + str(target_thing_title))
if fuzz.ratio(space_title, current_thing_title) > 85:
probable_thing_title = space_title
elif current_thing_title.startswith(target_thing_title):
if self.DEBUG:
print("partial match:" + str(len(current_thing_title) / len(target_thing_title)))
if len(current_thing_title) / len(target_thing_title) < 2:
# The strings mostly start the same, so this might be a match.
pass
elif target_thing_title == current_thing_title: # If the thing title is a perfect match
probable_thing_title = current_thing_title
if self.DEBUG:
print("FOUND THE CORRECT THING: " + str(current_thing_title))
elif fuzz.ratio(str(target_thing_title), current_thing_title) > 85: # If the title is a fuzzy match
if self.DEBUG:
print("This thing title is pretty similar, so it could be what we're looking for: " + str(current_thing_title))
probable_thing_title = current_thing_title
probable_thing_title_confidence = 85
elif target_space != None:
space_title = str(target_space) + " " + str(target_thing_title)
#if self.DEBUG:
# print("space title = " + str(target_space) + " + " + str(target_thing_title))
if fuzz.ratio(space_title, current_thing_title) > 85:
probable_thing_title = space_title
elif current_thing_title.startswith(target_thing_title):
if self.DEBUG:
print("partial match:" + str(len(current_thing_title) / len(target_thing_title)))
if len(current_thing_title) / len(target_thing_title) < 2:
# The strings mostly start the same, so this might be a match.
probable_thing_title = current_thing_title
probable_thing_title_confidence = 25
else:
# A title was provided, but we were not able to match it to the current things. Perhaps we can get a property-based match.
continue
except Exception as ex:
print("Error while trying to match title: " + str(ex))
def search_by_false_name(self, name, threshold=80):
"""Finds all items which match closely to all given query parameters.
Args:
name: Name to search by. Ignored if None.
threshold: Threshold for matching with RapidFuzz.
Returns:
List of matching triplets with NameItem, RapidFuzz ratio and RapidFuzz token_set_ratio
"""
matches = []
for item in self.items:
# Search with false name
ratio = fuzz.ratio(item.false_name, name)
token_set_ratio = fuzz.token_set_ratio(item.false_name.lower(), name.lower())
if ratio > threshold or token_set_ratio > threshold:
matches.append((item, ratio, token_set_ratio))
return sorted(matches, key=lambda x: x[1], reverse=True)