def translate(self, value): value = value.strip().lower() word = Word.query.filter_by(word=value).first() if word: word.power += 1 db.session.commit() return {'success': True, 'model': word} response = self.request(value) if response.status_code != 200: return {'success': False, 'message': response.json()['message']} word = Word() word.word = value word.definitions = response.json()['definitions'] db.session.add(word) db.session.commit() return {'success': True, 'model': word}
"definition": "the quantity contained in a bottle", "partOfSpeech": "noun" }, { "definition": "a vessel fitted with a flexible teat and filled with milk or formula; used as a substitute for breast feeding infants and very young children", "partOfSpeech": "noun" }, { "definition": "a glass or plastic vessel used for storing drinks or other liquids; typically cylindrical without handles and with a narrow neck that can be plugged or capped", "partOfSpeech": "noun" }, { "definition": "put into bottles", "partOfSpeech": "verb" }, { "definition": "store (liquids or gases) in bottles", "partOfSpeech": "verb" }] word_one = Word() word_one.word = "flask" word_one.definitions = definition_one word_two = Word() word_two.word = "bottle" word_two.definitions = definition_two db.session.add(word_one) db.session.add(word_two) db.session.commit()