MCPcopy Index your code
hub / github.com/InstaPy/InstaPy / lift_yandex_request

Function lift_yandex_request

instapy/text_analytics.py:416–458  ·  view source on GitHub ↗

Handle the Yandex status code from requests :return: Boolean indicating the state of request

(request)

Source from the content-addressed store, hash-verified

414
415
416def lift_yandex_request(request):
417 """
418 Handle the Yandex status code from requests
419
420 :return:
421 Boolean indicating the state of request
422 """
423
424 status_code = request["code"]
425 logger = Settings.logger
426
427 # handle per status code
428 if status_code in [401, 402, 404]:
429 # turn off Yandex service
430 YANDEX_CONFIG.update(enabled=False)
431 service_turnoff_msg = "turned off Yandex service"
432
433 if status_code == 401:
434 error_msg = "API key provided is invalid"
435 elif status_code == 402:
436 error_msg = "API key provided is blocked"
437 elif status_code == 404:
438 error_msg = "you've reached the request limit"
439
440 print("")
441 logger.error(
442 "{}\t~{} [{}]\n".format(YANDEX_FAILURE_MSG, error_msg, service_turnoff_msg)
443 )
444 return False
445
446 elif status_code in [413, 422, 501]:
447 if status_code == 413:
448 error_msg = "given text exceeds the maximum size :<"
449 elif status_code == 422:
450 error_msg = "given text couldn't be translated :("
451 elif status_code == 501:
452 error_msg = "the specified translation direction is not " "supported ~.~"
453
454 print("")
455 logger.error("{}\t~{}\n".format(YANDEX_FAILURE_MSG, error_msg))
456 return False
457
458 return True
459
460
461def lift_meaningcloud_request(request):

Callers 2

detect_languageFunction · 0.85
translate_textFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected