find_letter_image csvdriven.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #Cerca i file relativi alle immagini delle lettere DATINI e le copia
  2. #%%
  3. import csv
  4. from fileinput import filename
  5. import os
  6. import os.path
  7. import shutil
  8. output = open('datini_association_images_filename.csv', 'w')
  9. csvwriter = csv.writer(output)
  10. params = ['sigla','segnatura','Fondo','Busta','CODICE','filename_1','filename_2', 'filename_3', 'filename_4', 'filename_5', 'filename_6']
  11. csvwriter.writerow(params)
  12. def collate (filename):
  13. csv_filelist = open('C:\\Users\\OVI-CNR\\Desktop\\Immagini Datini\\filelist_images.csv')
  14. filelist = csv.DictReader(csv_filelist)
  15. for row in filelist:
  16. file = row['filename']
  17. filepath = row['filepath']
  18. if filename != "" and " ":
  19. if file.__contains__(filename):
  20. print (filename)
  21. shutil.copy(filepath, 'C:\\Users\\OVI-CNR\\Desktop\\extacted_images_new')
  22. return filename
  23. else:
  24. return "not found"
  25. #%%
  26. csv_lettere = open('/Users/federicaspinelli/TEAMOVI/Parser/DATA/Immagini_lettere_OVI_Datini/datini_associated_images.csv')
  27. reader = csv.DictReader(csv_lettere)
  28. for row in reader:
  29. line = []
  30. sigla = row['sigla']
  31. segnatura = row['segnatura']
  32. fondo = row['Fondo']
  33. busta = row['Busta']
  34. codice = row['CODICE']
  35. filename_1 = row['filename_1']
  36. filename_2 = row['filename_2']
  37. filename_3 = row['filename_3']
  38. filename_4 = row['filename_4']
  39. filename_5 = row['filename_5']
  40. filename_6 = row['filename_6']
  41. new_filename_1 = collate(filename_1)
  42. new_filename_2 = collate(filename_2)
  43. new_filename_3 = collate(filename_3)
  44. new_filename_4 = collate(filename_4)
  45. new_filename_5 = collate(filename_5)
  46. new_filename_6 = collate(filename_6)
  47. line.append(sigla)
  48. line.append(segnatura)
  49. line.append(fondo)
  50. line.append(busta)
  51. line.append(codice)
  52. line.append(new_filename_1)
  53. line.append(new_filename_2)
  54. line.append(new_filename_3)
  55. line.append(new_filename_4)
  56. line.append(new_filename_5)
  57. line.append(new_filename_6)
  58. csvwriter.writerow(line)
  59. output.close()
  60. #if filepath.__contains__(filename_5):