def _hint_message(self): uncommon_words = self.words - self.common_words hint = random.choice([word for word in uncommon_words]) hint_text = " ".join(redact_letters(hint, HINT_REDACTION_AMOUNT)) hint_definition = random.choice( [d for d in get_definition(hint).split("\n") if hint not in d]) return f"<em>Hint: {hint_text}</em>\n{hint_definition}"
def definition(self): if self._definition: return self._definition self.json = make_dict_request(self.name, DICT_API_KEY, REQ_URL) self._definition = get_definition(self.json) return self._definition
def _missed_words_message(self): remaining_words = self._longest_remaining_words() if not remaining_words: return message = "Here are some words you missed:" for word in remaining_words: definition = get_definition(word) if definition: word += "\n" + definition message += "\n\n" + word return message
def reply_message(msg): if (msg == 'news updates'): return news.news() if (msg.split()[0] == 'weather'): return weather.get_weather(msg.split()[1]) if (msg.split()[0] == 'definition'): return dictionary.get_definition(msg.split()[1]) if (msg.split()[0:2] == ['covid', 'update']): return tracker.get_corona_updates(msg.split()[2]) else: return "I dont understand"
def reply_message(msg): if(msg=='news updates'): return news.news() if(msg.split()[0]=='weather'): return weather.get_weather(msg.split()[1]) if(msg.split()[0]=='Weather'): return weather.get_weather(msg.split()[1]) if(msg.split()[0]=='definition'): return dictionary.get_definition(msg.split()[1]) if(msg.split()[0:2]==['covid','update']): return tracker.get_corona_updates(msg.split()[2]) else: return '''Hello, I am a WhatsApp Chatbot made by Vineet Kekatpure,Shreyash Joshi, Sandeep Suhag and Rithik Kalla.\n
def test_get_definition(): word = "apple" definition = get_definition(word) assert definition is not None assert isinstance(definition, str)
def test_get_definition_not_found(): word = "no such word" definition = get_definition(word) assert definition is None
def define_this(message): word = message.text[5:] definition = get_definition(word) bot.reply_to(message, definition)