Skip to content

Instantly share code, notes, and snippets.

@SyNeto
Created February 10, 2019 04:49
Show Gist options
  • Save SyNeto/aa0c39016bebe3e2675d3983b8848a7e to your computer and use it in GitHub Desktop.
Save SyNeto/aa0c39016bebe3e2675d3983b8848a7e to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import csv
import ntpath
import pathlib
import shutil
from unicodedata import normalize
def clean_string(text):
trans_tab = dict.fromkeys(map(ord, u'\u0301\u0308'), None)
text = text.replace(' ', '_')
text = text.replace('-', '_')
text = text.lower()
text = normalize('NFKC', normalize('NFKD', text).translate(trans_tab))
return text
if __name__ == '__main__':
with open('./portafolio.csv') as csv_file:
csv_reader = csv.reader(csv_file)
for row in csv_reader:
folder_name = clean_string(row[1])
destination_path = './imagenes_procesadas/{}/'.format(folder_name)
current_image_path = './imagenes-andamiaje/{}' .format(row[0])
file_name = ntpath.basename(current_image_path)
# create folder if not exists.
pathlib.Path(destination_path).mkdir(parents=True, exist_ok=True)
# copy file to destination.
try:
shutil.copy(current_image_path, destination_path + file_name)
except:
print("fail to move {}".format(current_image_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment