| 7 | |
| 8 | |
| 9 | class Translate: |
| 10 | |
| 11 | def __init__(self, file_name, word): |
| 12 | self.file_name = file_name |
| 13 | self.word = word |
| 14 | self.data = self.read_file() |
| 15 | |
| 16 | def read_file(self): |
| 17 | logging.debug(f"reading the file: {self.file_name}") |
| 18 | data = json.load(open(self.file_name)) |
| 19 | logging.debug(f'The type of data: {type(data)}') |
| 20 | return data |
| 21 | |
| 22 | def _translate(self): |
| 23 | word = str.lower(self.word) |
| 24 | if word in self.data: |
| 25 | logging.debug(f"Found the word({word}) in the json file...") |
| 26 | return self.data[word] |
| 27 | elif word.title() in self.data: |
| 28 | logging.debug(f"Found the word title({word.title()}) in the json file...") |
| 29 | return self.data[word.title()] |
| 30 | elif word.upper() in self.data: |
| 31 | logging.debug(f"Found the word upper({word.upper()}) in the json file...") |
| 32 | return self.data[word.upper()] |
| 33 | elif len(get_close_matches(word, self.data.keys())) > 0: |
| 34 | print("did you mean %s instead" % get_close_matches(word, self.data.keys())[0]) |
| 35 | decide = input("press y for yes or n for no: ") |
| 36 | if decide == "y": |
| 37 | return self.data[get_close_matches(word, self.data.keys())[0]] |
| 38 | elif decide == "n": |
| 39 | return ("pugger your paw steps on working keys ") |
| 40 | |
| 41 | else: |
| 42 | logging.debug(f"Couldn't find the word({word}) in the json file...") |
| 43 | |
| 44 | |
| 45 | |