associate_letter_filename.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #Cerca i file relativi alle immagini delle lettere DATINI a partire da CSV e le copia in una nuova directory
  2. #%%
  3. import csv
  4. import os
  5. import os.path
  6. import shutil
  7. output = open('datini_filecodes_complete.csv', 'w')
  8. csvwriter = csv.writer(output)
  9. params = ['sigla','segnatura','Fondo','Busta','CODICE','filename_1','filename_2', 'filename_3', 'filename_4', 'filename_5', 'filename_6',
  10. 'filename_7','filename_8', 'filename_9', 'filename_10', 'filename_11', 'filename_12', 'filename_13','filename_14', 'filename_15', 'filename_16', 'filename_17', 'filename_18',
  11. 'filename_19','filename_20', 'filename_21', 'filename_22', 'filename_23', 'filename_24', 'filename_25','filename_26', 'filename_27', 'filename_28', 'filename_29', 'filename_30',
  12. 'filename_31','filename_32', 'filename_33', 'filename_34', 'filename_35', 'filename_36', 'filename_37','filename_38', 'filename_39', 'filename_40']
  13. csvwriter.writerow(params)
  14. #%%
  15. def get_filename (codice, indice):
  16. filename = codice + indice + ".JPG"
  17. return filename
  18. csv_lettere = open('C:\\Users\\OVI-CNR\\Desktop\\Immagini Datini\\estrazione_immagini_complete.csv')
  19. reader = csv.DictReader(csv_lettere)
  20. for row in reader:
  21. line = []
  22. sigla = row['sigla']
  23. segnatura = row['segnatura']
  24. fondo = row['Fondo']
  25. busta = row['Busta']
  26. codice = row['CODICE']
  27. filename_1 = get_filename(codice, "01")
  28. filename_2 = get_filename(codice, "02")
  29. filename_3 = get_filename(codice, "03")
  30. filename_4 = get_filename(codice, "04")
  31. filename_5 = get_filename(codice, "05")
  32. filename_6 = get_filename(codice, "06")
  33. filename_7 = get_filename(codice, "07")
  34. filename_8 = get_filename(codice, "08")
  35. filename_9 = get_filename(codice, "09")
  36. filename_10 = get_filename(codice, "10")
  37. filename_11 = get_filename(codice, "11")
  38. filename_12 = get_filename(codice, "12")
  39. filename_13 = get_filename(codice, "13")
  40. filename_14 = get_filename(codice, "14")
  41. filename_15 = get_filename(codice, "15")
  42. filename_16 = get_filename(codice, "16")
  43. filename_17 = get_filename(codice, "17")
  44. filename_18 = get_filename(codice, "18")
  45. filename_19 = get_filename(codice, "19")
  46. filename_20 = get_filename(codice, "20")
  47. filename_21 = get_filename(codice, "21")
  48. filename_22 = get_filename(codice, "22")
  49. filename_23 = get_filename(codice, "23")
  50. filename_24 = get_filename(codice, "24")
  51. filename_25 = get_filename(codice, "25")
  52. filename_26 = get_filename(codice, "26")
  53. filename_27 = get_filename(codice, "27")
  54. filename_28 = get_filename(codice, "28")
  55. filename_29 = get_filename(codice, "29")
  56. filename_30 = get_filename(codice, "30")
  57. filename_31 = get_filename(codice, "31")
  58. filename_32 = get_filename(codice, "32")
  59. filename_33 = get_filename(codice, "33")
  60. filename_34 = get_filename(codice, "34")
  61. filename_35 = get_filename(codice, "35")
  62. filename_36 = get_filename(codice, "36")
  63. filename_37 = get_filename(codice, "37")
  64. filename_38 = get_filename(codice, "38")
  65. filename_39 = get_filename(codice, "39")
  66. filename_40 = get_filename(codice, "40")
  67. line.append(sigla)
  68. line.append(segnatura)
  69. line.append(fondo)
  70. line.append(busta)
  71. line.append(codice)
  72. line.append(filename_1)
  73. line.append(filename_2)
  74. line.append(filename_3)
  75. line.append(filename_4)
  76. line.append(filename_5)
  77. line.append(filename_6)
  78. line.append(filename_7)
  79. line.append(filename_8)
  80. line.append(filename_9)
  81. line.append(filename_10)
  82. line.append(filename_11)
  83. line.append(filename_12)
  84. line.append(filename_13)
  85. line.append(filename_14)
  86. line.append(filename_15)
  87. line.append(filename_16)
  88. line.append(filename_17)
  89. line.append(filename_18)
  90. line.append(filename_19)
  91. line.append(filename_20)
  92. line.append(filename_21)
  93. line.append(filename_22)
  94. line.append(filename_23)
  95. line.append(filename_24)
  96. line.append(filename_25)
  97. line.append(filename_26)
  98. line.append(filename_27)
  99. line.append(filename_28)
  100. line.append(filename_29)
  101. line.append(filename_30)
  102. line.append(filename_31)
  103. line.append(filename_32)
  104. line.append(filename_33)
  105. line.append(filename_34)
  106. line.append(filename_35)
  107. line.append(filename_36)
  108. line.append(filename_37)
  109. line.append(filename_38)
  110. line.append(filename_39)
  111. line.append(filename_40)
  112. csvwriter.writerow(line)
  113. output.close()