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():
    rs = os.walk('../../fashionbase/images/dataset_0520/xifu')
    for a, b, files in rs:
        print(a)
        for file in files:
            dir = '../../fashionbase/images/dataset_0520/xifu'.replace('dataset_0520', 'dataset_0520_10000')
            fold = os.path.exists(dir)
            if not fold:
                os.mkdir(dir)
            source_path = '../../fashionbase/images/dataset_0520/xifu/' + file
            target_path = source_path.replace('dataset_0520', 'dataset_0520_10000')

            source_path = source_path[3:]
            target_path = target_path[3:]
            print(source_path)
            print(target_path)
            # img_reproce.delay(source_path, target_path)
            write_redis(source_path, target_path)


if __name__ == '__main__':
    main()
