from api import get_result
import os
import shutil
from glob import glob
from PIL import Image

if __name__ == '__main__':
    image_files = glob('./test_images/*.*')
    result_dir = './test_results'
    if os.path.exists(result_dir):
        shutil.rmtree(result_dir)
    os.mkdir(result_dir)

    txt_file = os.path.join(result_dir, 'result.txt')
    txt_f = open(txt_file, 'w')

    for image_file in sorted(image_files):
        if ".gitkeep" in image_files:
            continue
        print("Finded file", image_file, end=" ")
        result = get_result(Image.open(image_file))
        print(":", result)
        txt_f.write(image_file.split('/')[-1].split('.')[0] + ':' + result + '\n')
    
    txt_f.close()
[((8, 18, 8, 43), 'glob.glob', 'glob', ({(8, 23, 8, 42): '"""./test_images/*.*"""'}, {}), "('./test_images/*.*')", False, 'from glob import glob\n'), ((10, 7, 10, 33), 'os.path.exists', 'os.path.exists', ({(10, 22, 10, 32): 'result_dir'}, {}), '(result_dir)', False, 'import os\n'), ((12, 4, 12, 24), 'os.mkdir', 'os.mkdir', ({(12, 13, 12, 23): 'result_dir'}, {}), '(result_dir)', False, 'import os\n'), ((14, 15, 14, 53), 'os.path.join', 'os.path.join', ({(14, 28, 14, 38): 'result_dir', (14, 40, 14, 52): '"""result.txt"""'}, {}), "(result_dir, 'result.txt')", False, 'import os\n'), ((11, 8, 11, 33), 'shutil.rmtree', 'shutil.rmtree', ({(11, 22, 11, 32): 'result_dir'}, {}), '(result_dir)', False, 'import shutil\n'), ((21, 28, 21, 50), 'PIL.Image.open', 'Image.open', ({(21, 39, 21, 49): 'image_file'}, {}), '(image_file)', False, 'from PIL import Image\n')]