From 950541d16fcb605593f1bfaeef94501df6ea91c4 Mon Sep 17 00:00:00 2001 From: Lukas Ruzicka Date: Aug 20 2019 13:55:19 +0000 Subject: Add support for partial matches. --- diff --git a/needle_mapper.py b/needle_mapper.py index 8c5933b..456feaa 100755 --- a/needle_mapper.py +++ b/needle_mapper.py @@ -44,7 +44,8 @@ class FileReader: def __init__(self, paths): """ Initializes the class with all possible paths. """ self.paths = paths - self.foundin = [] + self.exact = [] + self.similar = [] def read_json(self, path): """ Reads a file from the path and return a dictionary. """ @@ -59,8 +60,12 @@ class FileReader: for path in self.paths: content = self.read_json(path) if tagtofind in content['tags']: - self.foundin.append(path) - return self.foundin + self.exact.append(path) + else: + for tag in content['tags']: + if tagtofind in tag: + self.similar.append(path) + return (self.exact, self.similar) def main(): """ Main program """ @@ -78,10 +83,16 @@ def main(): reader = FileReader(tree.return_paths()) print(f"I am searching for '{tag}' in {count} files.") print('==================================================') - print("The following files have that tag:") locations = reader.find_tag(tag) - for location in locations: - print(location) + exact = locations[0] + similar = locations[1] + print("The following files have an exact tag:") + for path in exact: + print(path) + print('--------------------------------------------------') + print("The following files have a similar tag:") + for path in similar: + print(path)