def read_info(root): infos = [] for item in os.listdir(root): path = os.path.join(root, item) with open(path, "rb") as fp: info = exif.parse_exif(fp) m = re.match(r"(\d{8}) \- (.+).jpg", item) if m: info["time"] = m.group(1) info["name"] = m.group(2) for it in infos: if it["name"] == info["name"] and safe_get(info, "status") != "dup": print("dup: %s" % info) info["status"] = "dup" update_pic(path, info) break else: infos.append(info) return infos
new_name = guess_name(infos, fn) if not new_name: print("%s not matched" % fn) else: new_abs_path = os.path.join(conf.root, new_name) if new_name != fn and not os.path.exists(new_abs_path): os.renames(abs_path, new_abs_path) print("%s --> %s" % (fn, new_name)) statistic = {"true":0, "never":0, "undefined":0, "dup":0} for info in infos: if "status" in info and info["status"] in statistic: statistic[info["status"]] += 1 else: name = info2name(info) for fn in os.listdir(conf.root): if os.path.isfile(os.path.join(conf.root, fn)): if fn.startswith(name): # update pic_name = "%s - %s.%s" % (info["time"], info["name"], "jpg") pic_abs_path = os.path.join(conf.pic_root, pic_name) with open(pic_abs_path, "rb") as fp: exif_meta = exif.parse_exif(fp) exif_meta["status"] = "true" update_pic(pic_abs_path, exif_meta) statistic["true"] += 1 break else: print("undefined art: %s - %s" % (info["name"], info["time"])) statistic["undefined"] += 1 print(statistic)