# -*- 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, 'ais_sdk.utils.init_global_env', 'init_global_env', False, 'from ais_sdk.utils import init_global_env\n'), (19, 'ais_sdk.distortion_correct.distortion_correct_aksk', 'distortion_correct_aksk', False, 'from ais_sdk.distortion_correct import distortion_correct_aksk\n'), (20, 'json.loads', 'json.loads', False, 'import json\n'), (28, 'json.loads', 'json.loads', False, 'import json\n'), (22, 'ais_sdk.utils.decode_to_wave_file', 'decode_to_wave_file', False, 'from ais_sdk.utils import decode_to_wave_file\n'), (27, 'ais_sdk.utils.encode_to_base64', 'encode_to_base64', False, 'from ais_sdk.utils import encode_to_base64\n'), (30, 'ais_sdk.utils.decode_to_wave_file', 'decode_to_wave_file', False, 'from ais_sdk.utils import decode_to_wave_file\n')]