import sys
sys.path.append("..")

import os
from proj.tasks import img_reproce


def write_redis(source_path, target_path):
    i = 0
    while i < 3:
        try:
            r = img_reproce.apply_async(args=[source_path, target_path])
            return r
        except:
            i += 1


def main():
    path = '/data/images/dataset_0523/'
    rs = os.walk(path)
    for a, b, files in rs:
        if b == []:
            for file in files[:5000]:
                dir = a.replace('dataset_0523', 'dataset_0523_first')
                fold = os.path.exists(dir)
                if not fold:
                    os.mkdir(dir)
                source_path = a + file
                target_path = dir + file

                print(source_path)
                print(target_path)
                #write_redis(source_path, target_path)


if __name__ == '__main__':
    main()
