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, 'glob.glob', 'glob', False, 'from glob import glob\n'), (10, 'os.path.exists', 'os.path.exists', False, 'import os\n'), (12, 'os.mkdir', 'os.mkdir', False, 'import os\n'), (14, 'os.path.join', 'os.path.join', False, 'import os\n'), (11, 'shutil.rmtree', 'shutil.rmtree', False, 'import shutil\n'), (21, 'PIL.Image.open', 'Image.open', False, 'from PIL import Image\n')]