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()
[((141, 166), 'glob.glob', 'glob', (['"""./test_images/*.*"""'], {}), "('./test_images/*.*')\n", (145, 166), False, 'from glob import glob\n'), ((208, 234), 'os.path.exists', 'os.path.exists', (['result_dir'], {}), '(result_dir)\n', (222, 234), False, 'import os\n'), ((274, 294), 'os.mkdir', 'os.mkdir', (['result_dir'], {}), '(result_dir)\n', (282, 294), False, 'import os\n'), ((311, 349), 'os.path.join', 'os.path.join', (['result_dir', '"""result.txt"""'], {}), "(result_dir, 'result.txt')\n", (323, 349), False, 'import os\n'), ((244, 269), 'shutil.rmtree', 'shutil.rmtree', (['result_dir'], {}), '(result_dir)\n', (257, 269), False, 'import shutil\n'), ((563, 585), 'PIL.Image.open', 'Image.open', (['image_file'], {}), '(image_file)\n', (573, 585), False, 'from PIL import Image\n')]