123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- #Cerca i file relativi alle immagini delle lettere DATINI a partire da CSV e le copia in una nuova directory
- #%%
- import csv
- import os
- import os.path
- import shutil
- # output = open('datini_filecodes_complete.csv', 'w')
- # csvwriter = csv.writer(output)
- # params = ['sigla','segnatura','Fondo','Busta','CODICE','filename_1','filename_2', 'filename_3', 'filename_4', 'filename_5', 'filename_6',
- # 'filename_7','filename_8', 'filename_9', 'filename_10', 'filename_11', 'filename_12', 'filename_13','filename_14', 'filename_15', 'filename_16', 'filename_17', 'filename_18',
- # 'filename_19','filename_20', 'filename_21', 'filename_22', 'filename_23', 'filename_24', 'filename_25','filename_26', 'filename_27', 'filename_28', 'filename_29', 'filename_30',
- # 'filename_31','filename_32', 'filename_33', 'filename_34', 'filename_35', 'filename_36', 'filename_37','filename_38', 'filename_39', 'filename_40']
- # csvwriter.writerow(params)
- #%%
- def get_filename (codice, indice):
- filecodex= codice + indice + ".JPG"
- return filecodex
- csv_lettere = open('/Users/federicaspinelli/TEAMOVI/Parser/DATA/Immagini_lettere_OVI_Datini/datini_filecodes_complete.csv')
- reader = csv.DictReader(csv_lettere)
- for row in reader:
- line = []
- sigla = row['sigla']
- segnatura = row['segnatura']
- fondo = row['Fondo']
- busta = row['Busta']
- codice = row['CODICE']
- filename_1 = get_filename(codice, "01")
- filename_2 = get_filename(codice, "02")
- filename_3 = get_filename(codice, "03")
- filename_4 = get_filename(codice, "04")
- filename_5 = get_filename(codice, "05")
- filename_6 = get_filename(codice, "06")
- filename_7 = get_filename(codice, "07")
- filename_8 = get_filename(codice, "08")
- filename_9 = get_filename(codice, "09")
- filename_10 = get_filename(codice, "10")
- filename_11 = get_filename(codice, "11")
- filename_12 = get_filename(codice, "12")
- filename_13 = get_filename(codice, "13")
- filename_14 = get_filename(codice, "14")
- filename_15 = get_filename(codice, "15")
- filename_16 = get_filename(codice, "16")
- filename_17 = get_filename(codice, "17")
- filename_18 = get_filename(codice, "18")
- filename_19 = get_filename(codice, "19")
- filename_20 = get_filename(codice, "20")
- filename_21 = get_filename(codice, "21")
- filename_22 = get_filename(codice, "22")
- filename_23 = get_filename(codice, "23")
- filename_24 = get_filename(codice, "24")
- filename_25 = get_filename(codice, "25")
- filename_26 = get_filename(codice, "26")
- filename_27 = get_filename(codice, "27")
- filename_28 = get_filename(codice, "28")
- filename_29 = get_filename(codice, "29")
- filename_30 = get_filename(codice, "30")
- filename_31 = get_filename(codice, "31")
- filename_32 = get_filename(codice, "32")
- filename_33 = get_filename(codice, "33")
- filename_34 = get_filename(codice, "34")
- filename_35 = get_filename(codice, "35")
- filename_36 = get_filename(codice, "36")
- filename_37 = get_filename(codice, "37")
- filename_38 = get_filename(codice, "38")
- filename_39 = get_filename(codice, "39")
- filename_40 = get_filename(codice, "40")
- folder = "/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/missing"
- files = os.listdir(folder)
-
- for filename in files:
- if filename == filename_1:
- dst =f""+sigla+"_01"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- print('Sostituzione' + src + ' ' + dst)
- elif filename == filename_2:
- dst =f""+sigla+"_02"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- print('Sostituzione' + src + ' ' + dst)
- elif filename == filename_3:
- dst =f""+sigla+"_03"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- print('Sostituzione' + src + ' ' + dst)
- # # rename() function will
- # # rename all the files
- os.rename(src, dst)
- elif filename == filename_4:
- dst =f""+sigla+"_04"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_5:
- dst =f""+sigla+"_05"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_6:
- dst =f""+sigla+"_06"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_7:
- dst =f""+sigla+"_07"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_8 :
- dst =f""+sigla+"_08"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_9:
- dst =f""+sigla+"_09"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_10:
- dst =f""+sigla+"_10"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_11:
- dst =f""+sigla+"_11"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_12:
- dst =f""+sigla+"_12"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_13:
- dst =f""+sigla+"_13"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_14 :
- dst =f""+sigla+"_14"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_15:
- dst =f""+sigla+"_15"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_16:
- dst =f""+sigla+"_16"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_17:
- dst =f""+sigla+"_17"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_18:
- dst =f""+sigla+"_18"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_19 :
- dst =f""+sigla+"_19"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_20:
- dst =f""+sigla+"_20"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_21:
- dst =f""+sigla+"_21"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_22:
- dst =f""+sigla+"_22"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_23:
- dst =f""+sigla+"_23"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_24 :
- dst =f""+sigla+"_24"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_25:
- dst =f""+sigla+"_25"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_26:
- dst =f""+sigla+"_26"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_27:
- dst =f""+sigla+"_27"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_28:
- dst =f""+sigla+"_28"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_29 :
- dst =f""+sigla+"_29"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_30:
- dst =f""+sigla+"_30"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_31:
- dst =f""+sigla+"_31"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_32:
- dst =f""+sigla+"_32"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_33:
- dst =f""+sigla+"_33"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_34 :
- dst =f""+sigla+"_34"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_35:
- dst =f""+sigla+"_35"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_36:
- dst =f""+sigla+"_36"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_37:
- dst =f""+sigla+"_37"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_38:
- dst =f""+sigla+"_38"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_39 :
- dst =f""+sigla+"_39"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- elif filename == filename_40 :
- dst =f""+sigla+"_40"+".jpg"
- src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- dst =f"{folder}/{dst}"
- # rename() function will
- # rename all the files
- os.rename(src, dst)
- # else :
- # dst =f""+filename+"_NO_SIGLA"+".jpg"
- # src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
- # dst =f"{folder}/{dst}"
- # # rename() function will
- # # rename all the files
- # os.rename(src, dst)
|