Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except QueryError as exception:
raise NotFoundError(exception.word)
content_json = json.loads(content)
status = content_json.get('code')
if status != 200:
# https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/#codes
message = self.status_code.get(
status,
'Some bad thing happened with Yandex'
)
print('Yandex: ' + message)
raise NotFoundError(word)
record = Record(
word=word,
content=content,
source=self.provider,
)
return record
def query(self, word: str):
content_str = self._get_raw(word)
content_dict = json.loads(content_str)
if content_dict['list'] == []:
raise NotFoundError(word)
record = Record(
word=word,
content=content_str,
source=self.provider,
)
return record
def query(self, word: str):
try:
app_id, app_key = self._get_app_key()
content = self._get_raw(word, headers={
'app_id': app_id,
'app_key': app_key
})
except QueryError as exception:
msg = self.status_code.get(exception.status_code,
'Some bad thing happened')
self.color.print('Oxford: ' + msg, 'red')
raise NotFoundError(exception.word)
record = Record(
word=word,
content=content,
source=self.provider,
)
return record
# Construct summary (required)
try:
content['summary'] = self.parse_summary(data, word)
except AttributeError:
raise NotFoundError(word)
# Handle explain (required)
try:
content['explain'] = self.parse_explain(data)
except IndexError:
raise NotFoundError(word)
# Extract verbose (optional)
content['verbose'] = self.parse_verbose(data)
record = Record(
word=word,
content=json.dumps(content),
source=self.provider,
)
return record
def query(self, word: str):
try:
content = self._get_raw(word)
except QueryError as exception:
raise NotFoundError(exception.word)
record = Record(
word=word,
content=content,
source=self.provider,
)
return record