# -*- coding:utf-8 -*-
from ais_sdk.utils import encode_to_base64
from ais_sdk.utils import decode_to_wave_file
from ais_sdk.distortion_correct import distortion_correct_aksk
from ais_sdk.utils import init_global_env
import json

if __name__ == '__main__':
    #
    # access moderation distortion correct.post data by ak,sk
    #
    app_key = '*************'
    app_secret = '************'
    init_global_env(region='cn-north-1')

    demo_data_url = 'https://ais-sample-data.obs.cn-north-1.myhuaweicloud.com/vat-invoice.jpg'

    #call interface use the url correction is true means do not correction
    result = distortion_correct_aksk(app_key, app_secret, "", demo_data_url, True)
    result_obj = json.loads(result)
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'], 'data/moderation-distortion-aksk-1.png')
    else:
        print(result)

    # call interface use the file
    result = distortion_correct_aksk(app_key, app_secret, encode_to_base64('data/moderation-distortion.jpg'), '', True)
    result_obj = json.loads(result)
    if result_obj['result']['data'] != '':
        decode_to_wave_file(result_obj['result']['data'], 'data/moderation-distortion-aksk-2.png')
    else:
        print(result)
[((14, 4, 14, 40), 'ais_sdk.utils.init_global_env', 'init_global_env', (), '', False, 'from ais_sdk.utils import init_global_env\n'), ((19, 13, 19, 82), 'ais_sdk.distortion_correct.distortion_correct_aksk', 'distortion_correct_aksk', ({(19, 37, 19, 44): 'app_key', (19, 46, 19, 56): 'app_secret', (19, 58, 19, 60): '""""""', (19, 62, 19, 75): 'demo_data_url', (19, 77, 19, 81): 'True'}, {}), "(app_key, app_secret, '', demo_data_url, True)", False, 'from ais_sdk.distortion_correct import distortion_correct_aksk\n'), ((20, 17, 20, 35), 'json.loads', 'json.loads', ({(20, 28, 20, 34): 'result'}, {}), '(result)', False, 'import json\n'), ((28, 17, 28, 35), 'json.loads', 'json.loads', ({(28, 28, 28, 34): 'result'}, {}), '(result)', False, 'import json\n'), ((22, 8, 22, 98), 'ais_sdk.utils.decode_to_wave_file', 'decode_to_wave_file', ({(22, 28, 22, 56): "result_obj['result']['data']", (22, 58, 22, 97): '"""data/moderation-distortion-aksk-1.png"""'}, {}), "(result_obj['result']['data'],\n    'data/moderation-distortion-aksk-1.png')", False, 'from ais_sdk.utils import decode_to_wave_file\n'), ((27, 58, 27, 108), 'ais_sdk.utils.encode_to_base64', 'encode_to_base64', ({(27, 75, 27, 107): '"""data/moderation-distortion.jpg"""'}, {}), "('data/moderation-distortion.jpg')", False, 'from ais_sdk.utils import encode_to_base64\n'), ((30, 8, 30, 98), 'ais_sdk.utils.decode_to_wave_file', 'decode_to_wave_file', ({(30, 28, 30, 56): "result_obj['result']['data']", (30, 58, 30, 97): '"""data/moderation-distortion-aksk-2.png"""'}, {}), "(result_obj['result']['data'],\n    'data/moderation-distortion-aksk-2.png')", False, 'from ais_sdk.utils import decode_to_wave_file\n')]