def create_counters_csv_per_dir(): """ extract counter from the file name write a csv file with those counters for each directory This csv can be modified to be used with :func:`write_exif_using_csv` If you want to modify it with EXCEL or Calc take care to import all columns of the csv as text. """ log_function_call(create_tags_csv_per_dir.__name__) inpath = os.getcwd() tag_set_names = OrderedSet() out_filename = get_info_dir("tags_counters.csv") csvfile, writer = fileop.create_csv_writer(out_filename, [ "directory", "name_main", "name_part", "first", "last", "tags3", "description" ]) for (dirpath, dirnames, filenames) in os.walk(inpath): if not inpath == dirpath: continue for dirname in dirnames: filenameAccessors = [ FilenameAccessor(filename) for filename in get_plain_filenames_of_type( image_types, dirpath, dirname) ] if len(filenameAccessors) == 0: continue _add_counter_csv_entries(dirname, filenameAccessors, tag_set_names) writer.writerows(tag_set_names) csvfile.close()
def create_tags_csv(location: str = ""): """ extract tags from the file name write a csv file with those tags :param location: optional content of directory column This csv can be modified to be used with :func:`write_exif_using_csv` or :func:`placeinfo.write_infos` If you want to modify it with EXCEL or Calc take care to import all columns of the csv as text. """ inpath = os.getcwd() tag_set = OrderedSet() tag_set_names = OrderedSet() out_filename = get_info_dir("tags_places.csv") tags_places_file, writer = fileop.create_csv_writer( out_filename, ["directory", "name_part"]) filenameAccessors = [ FilenameAccessor(filename) for filename in get_plain_filenames_of_type(image_types, inpath) ] for fileNameAccessor in filenameAccessors: for tag in fileNameAccessor.tags(): tag_set.add(tag) writeToFile(get_info_dir("tags.txt"), location + "\n\t" + "\n\t".join(tag_set) + "\n") for tag in tag_set: tag_set_names.add((location, tag)) writer.writerows(tag_set_names) tags_places_file.close()
def create_rating_csv(rating: int = 4, subdir: str = ""): """ creates a csv file with all files in the directory the rating column is filled with param rating :param rating: rating to be written :param subdir: sub directory to make rating file of, if empty all directories will be taken """ log_function_call(create_rating_csv.__name__, rating, subdir) inpath = os.getcwd() out_filebasename = "rating" if subdir: out_filebasename += "_" + subdir out_filename = get_setexif_dir(out_filebasename + ".csv") rating_file, writer = fileop.create_csv_writer(out_filename, ["name_part", "rating"]) for (dirpath, dirnames, filenames) in os.walk(os.path.join(inpath, subdir)): if is_invalid_path(dirpath): continue for filename in filterFiles(filenames, settings.image_types): writer.writerow([filename, rating]) rating_file.close()
def create_names_csv_per_dir(start_after_dir=''): """ extract names from the file path write a csv file with those names for each directory This csv can be modified to be used with :func:`write_exif_using_csv` If you want to modify it with EXCEL or Calc take care to import all columns of the csv as text. """ log_function_call(create_names_csv_per_dir.__name__) inpath = os.getcwd() tag_set_names = OrderedSet() out_filename = get_info_dir("tags_names.csv") csvfile, writer = fileop.create_csv_writer( out_filename, ["directory", "name_main", "tags"]) for (dirpath, dirnames, filenames) in os.walk(inpath): if is_invalid_path(dirpath): continue filenameAccessors = [ FilenameAccessor(filename) for filename in filterFiles(filenames, image_types) ] if len(filenameAccessors) == 0: continue tags = [] found = False for part in dirpath.split(os.sep): if found: tags += part.split(', ') else: found = part == start_after_dir filenameAccessorLast = filenameAccessors[0] tag_set_names.add( (", ".join(tags), filenameAccessorLast.pre, ', '.join(OrderedSet(tags + [filenameAccessorLast.pre])))) for filenameAccessor in filenameAccessors[1:]: if not filenameAccessor.pre == filenameAccessorLast.pre: tag_set_names.add( (", ".join(tags), filenameAccessor.pre, ', '.join(OrderedSet(tags + [filenameAccessor.pre])))) filenameAccessorLast = filenameAccessor writer.writerows(tag_set_names) csvfile.close()
def create_tags_csv_per_dir(): """ extract tags from the file name write a csv file with those tags and group them by toplevel directory This csv can be modified to be used with :func:`write_exif_using_csv` or :func:`placeinfo.write_infos` If you want to modify it with EXCEL or Calc take care to import all columns of the csv as text. """ log_function_call(create_tags_csv_per_dir.__name__) inpath = os.getcwd() tag_set_names = OrderedSet() out_filename = get_info_dir("tags_per_dir.csv") tags_places_file, writer = fileop.create_csv_writer( out_filename, ["directory", "name_part"]) for (dirpath, dirnames, filenames) in os.walk(inpath): if not inpath == dirpath: continue for dirname in dirnames: tag_set = OrderedSet() filenameAccessors = [ FilenameAccessor(filename) for filename in get_plain_filenames_of_type( image_types, dirpath, dirname) ] if len(filenameAccessors) == 0: continue for fileNameAccessor in filenameAccessors: for tag in fileNameAccessor.tags(): tag_set.add(tag) writeToFile(get_info_dir("tags.txt"), dirname + "\n\t" + "\n\t".join(tag_set) + "\n") dirname_split = dirname.split("_") subnames = [ subname for subname in dirname_split if not subname.isnumeric() ] dirname = "_".join(subnames) for tag in tag_set: tag_set_names.add((dirname, tag)) writer.writerows(tag_set_names) tags_places_file.close()
def _create_empty_csv(name: str, columns: Iterable): filename = get_setexif_dir(name + ".csv") if isfile(filename): return csv_file, writer = fileop.create_csv_writer(filename, columns) csv_file.close()
def find_bad_exif(do_move=True, check_date_additional=False, folder: str = r""): """ find files with missing exif data """ log_function_call(find_bad_exif.__name__, do_move) clock = Clock() inpath = os.getcwd() lines_no_tags = OrderedSet() lines_bad_date_additional = OrderedSet() lines_date_missing = OrderedSet() out_filename_no_tags = get_info_dir("no_tags.csv") file_no_tags, writer_no_tags = fileop.create_csv_writer( out_filename_no_tags, ["directory", "name_part"]) out_filename_bad_date_additional = get_info_dir("bad_date_additional.csv") file_bad_date_additional, writer_bad_date_additional = fileop.create_csv_writer( out_filename_bad_date_additional, ["directory", "name_part"]) out_filename_date_missing = get_info_dir("date_missing.csv") file_date_missing, writer_date_missing = fileop.create_csv_writer( out_filename_date_missing, ["directory", "name_part"]) for (dirpath, dirnames, filenames) in os.walk(inpath): if is_invalid_path(dirpath, regex=folder): continue if fileop.count_files(filenames, settings.image_types) == 0: continue Tagdict = read_exiftags(dirpath, settings.image_types, ask=False) if len(list(Tagdict.values())) == 0: continue leng = len(list(Tagdict.values())[0]) for i in range(leng): if (not "Keywords" in Tagdict or not Tagdict["Keywords"][i]) or \ (not "Subject" in Tagdict or not Tagdict["Subject"][i]) or \ (not "Description" in Tagdict or not Tagdict["Description"][i]) or \ (not "User Comment" in Tagdict or not Tagdict["User Comment"][i]): lines_no_tags.add((os.path.basename(dirpath), _remove_counter(Tagdict["File Name"][i]))) if do_move and not "bad_exif" in dirpath: move( Tagdict["File Name"][i], dirpath, dirpath.replace( inpath, os.path.join(inpath, "bad_exif_keywords"))) if not "Date/Time Original" in Tagdict or not Tagdict[ "Date/Time Original"][i]: lines_date_missing.add( (os.path.basename(dirpath), _remove_counter(Tagdict["File Name"][i]))) if do_move and not "bad_exif" in dirpath: move( Tagdict["File Name"][i], dirpath, dirpath.replace( inpath, os.path.join(inpath, "bad_exif_date_missing"))) if check_date_additional and \ (("Date Created" in Tagdict and Tagdict["Date Created"][i]) or ("Time Created" in Tagdict and Tagdict["Time Created"][i]) or ("Create Date" in Tagdict and Tagdict["Create Date"][i]) or ("Modify Date" in Tagdict and Tagdict["Modify Date"][i]) or ("Digital Creation Date" in Tagdict and Tagdict["Digital Creation Date"][i])): lines_bad_date_additional.add( (os.path.basename(dirpath), _remove_counter(Tagdict["File Name"][i]))) if do_move and not "bad_exif" in dirpath: move( Tagdict["File Name"][i], dirpath, dirpath.replace( inpath, os.path.join(inpath, "bad_exif_date_additional"))) writer_no_tags.writerows(lines_no_tags) writer_bad_date_additional.writerows(lines_bad_date_additional) writer_date_missing.writerows(lines_date_missing) file_no_tags.close() file_bad_date_additional.close() file_date_missing.close() clock.finish()