associate_codice_sigla.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. filecodex= codice + indice + ".JPG"
  17. return filecodex
  18. csv_lettere = open('/Users/federicaspinelli/TEAMOVI/Parser/DATA/Immagini_lettere_OVI_Datini/datini_filecodes_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. folder = "/Volumes/GoogleDrive-117836417327186331381/Il mio Drive/OVI-CNR/missing"
  68. files = os.listdir(folder)
  69. for filename in files:
  70. if filename == filename_1:
  71. dst =f""+sigla+"_01"+".jpg"
  72. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  73. dst =f"{folder}/{dst}"
  74. # rename() function will
  75. # rename all the files
  76. os.rename(src, dst)
  77. print('Sostituzione' + src + ' ' + dst)
  78. elif filename == filename_2:
  79. dst =f""+sigla+"_02"+".jpg"
  80. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  81. dst =f"{folder}/{dst}"
  82. # rename() function will
  83. # rename all the files
  84. os.rename(src, dst)
  85. print('Sostituzione' + src + ' ' + dst)
  86. elif filename == filename_3:
  87. dst =f""+sigla+"_03"+".jpg"
  88. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  89. dst =f"{folder}/{dst}"
  90. print('Sostituzione' + src + ' ' + dst)
  91. # # rename() function will
  92. # # rename all the files
  93. os.rename(src, dst)
  94. elif filename == filename_4:
  95. dst =f""+sigla+"_04"+".jpg"
  96. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  97. dst =f"{folder}/{dst}"
  98. # rename() function will
  99. # rename all the files
  100. os.rename(src, dst)
  101. elif filename == filename_5:
  102. dst =f""+sigla+"_05"+".jpg"
  103. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  104. dst =f"{folder}/{dst}"
  105. # rename() function will
  106. # rename all the files
  107. os.rename(src, dst)
  108. elif filename == filename_6:
  109. dst =f""+sigla+"_06"+".jpg"
  110. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  111. dst =f"{folder}/{dst}"
  112. # rename() function will
  113. # rename all the files
  114. os.rename(src, dst)
  115. elif filename == filename_7:
  116. dst =f""+sigla+"_07"+".jpg"
  117. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  118. dst =f"{folder}/{dst}"
  119. # rename() function will
  120. # rename all the files
  121. os.rename(src, dst)
  122. elif filename == filename_8 :
  123. dst =f""+sigla+"_08"+".jpg"
  124. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  125. dst =f"{folder}/{dst}"
  126. # rename() function will
  127. # rename all the files
  128. os.rename(src, dst)
  129. elif filename == filename_9:
  130. dst =f""+sigla+"_09"+".jpg"
  131. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  132. dst =f"{folder}/{dst}"
  133. # rename() function will
  134. # rename all the files
  135. os.rename(src, dst)
  136. elif filename == filename_10:
  137. dst =f""+sigla+"_10"+".jpg"
  138. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  139. dst =f"{folder}/{dst}"
  140. # rename() function will
  141. # rename all the files
  142. os.rename(src, dst)
  143. elif filename == filename_11:
  144. dst =f""+sigla+"_11"+".jpg"
  145. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  146. dst =f"{folder}/{dst}"
  147. # rename() function will
  148. # rename all the files
  149. os.rename(src, dst)
  150. elif filename == filename_12:
  151. dst =f""+sigla+"_12"+".jpg"
  152. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  153. dst =f"{folder}/{dst}"
  154. # rename() function will
  155. # rename all the files
  156. os.rename(src, dst)
  157. elif filename == filename_13:
  158. dst =f""+sigla+"_13"+".jpg"
  159. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  160. dst =f"{folder}/{dst}"
  161. # rename() function will
  162. # rename all the files
  163. os.rename(src, dst)
  164. elif filename == filename_14 :
  165. dst =f""+sigla+"_14"+".jpg"
  166. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  167. dst =f"{folder}/{dst}"
  168. # rename() function will
  169. # rename all the files
  170. os.rename(src, dst)
  171. elif filename == filename_15:
  172. dst =f""+sigla+"_15"+".jpg"
  173. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  174. dst =f"{folder}/{dst}"
  175. # rename() function will
  176. # rename all the files
  177. os.rename(src, dst)
  178. elif filename == filename_16:
  179. dst =f""+sigla+"_16"+".jpg"
  180. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  181. dst =f"{folder}/{dst}"
  182. # rename() function will
  183. # rename all the files
  184. os.rename(src, dst)
  185. elif filename == filename_17:
  186. dst =f""+sigla+"_17"+".jpg"
  187. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  188. dst =f"{folder}/{dst}"
  189. # rename() function will
  190. # rename all the files
  191. os.rename(src, dst)
  192. elif filename == filename_18:
  193. dst =f""+sigla+"_18"+".jpg"
  194. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  195. dst =f"{folder}/{dst}"
  196. # rename() function will
  197. # rename all the files
  198. os.rename(src, dst)
  199. elif filename == filename_19 :
  200. dst =f""+sigla+"_19"+".jpg"
  201. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  202. dst =f"{folder}/{dst}"
  203. # rename() function will
  204. # rename all the files
  205. os.rename(src, dst)
  206. elif filename == filename_20:
  207. dst =f""+sigla+"_20"+".jpg"
  208. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  209. dst =f"{folder}/{dst}"
  210. # rename() function will
  211. # rename all the files
  212. os.rename(src, dst)
  213. elif filename == filename_21:
  214. dst =f""+sigla+"_21"+".jpg"
  215. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  216. dst =f"{folder}/{dst}"
  217. # rename() function will
  218. # rename all the files
  219. os.rename(src, dst)
  220. elif filename == filename_22:
  221. dst =f""+sigla+"_22"+".jpg"
  222. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  223. dst =f"{folder}/{dst}"
  224. # rename() function will
  225. # rename all the files
  226. os.rename(src, dst)
  227. elif filename == filename_23:
  228. dst =f""+sigla+"_23"+".jpg"
  229. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  230. dst =f"{folder}/{dst}"
  231. # rename() function will
  232. # rename all the files
  233. os.rename(src, dst)
  234. elif filename == filename_24 :
  235. dst =f""+sigla+"_24"+".jpg"
  236. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  237. dst =f"{folder}/{dst}"
  238. # rename() function will
  239. # rename all the files
  240. os.rename(src, dst)
  241. elif filename == filename_25:
  242. dst =f""+sigla+"_25"+".jpg"
  243. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  244. dst =f"{folder}/{dst}"
  245. # rename() function will
  246. # rename all the files
  247. os.rename(src, dst)
  248. elif filename == filename_26:
  249. dst =f""+sigla+"_26"+".jpg"
  250. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  251. dst =f"{folder}/{dst}"
  252. # rename() function will
  253. # rename all the files
  254. os.rename(src, dst)
  255. elif filename == filename_27:
  256. dst =f""+sigla+"_27"+".jpg"
  257. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  258. dst =f"{folder}/{dst}"
  259. # rename() function will
  260. # rename all the files
  261. os.rename(src, dst)
  262. elif filename == filename_28:
  263. dst =f""+sigla+"_28"+".jpg"
  264. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  265. dst =f"{folder}/{dst}"
  266. # rename() function will
  267. # rename all the files
  268. os.rename(src, dst)
  269. elif filename == filename_29 :
  270. dst =f""+sigla+"_29"+".jpg"
  271. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  272. dst =f"{folder}/{dst}"
  273. # rename() function will
  274. # rename all the files
  275. os.rename(src, dst)
  276. elif filename == filename_30:
  277. dst =f""+sigla+"_30"+".jpg"
  278. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  279. dst =f"{folder}/{dst}"
  280. # rename() function will
  281. # rename all the files
  282. os.rename(src, dst)
  283. elif filename == filename_31:
  284. dst =f""+sigla+"_31"+".jpg"
  285. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  286. dst =f"{folder}/{dst}"
  287. # rename() function will
  288. # rename all the files
  289. os.rename(src, dst)
  290. elif filename == filename_32:
  291. dst =f""+sigla+"_32"+".jpg"
  292. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  293. dst =f"{folder}/{dst}"
  294. # rename() function will
  295. # rename all the files
  296. os.rename(src, dst)
  297. elif filename == filename_33:
  298. dst =f""+sigla+"_33"+".jpg"
  299. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  300. dst =f"{folder}/{dst}"
  301. # rename() function will
  302. # rename all the files
  303. os.rename(src, dst)
  304. elif filename == filename_34 :
  305. dst =f""+sigla+"_34"+".jpg"
  306. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  307. dst =f"{folder}/{dst}"
  308. # rename() function will
  309. # rename all the files
  310. os.rename(src, dst)
  311. elif filename == filename_35:
  312. dst =f""+sigla+"_35"+".jpg"
  313. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  314. dst =f"{folder}/{dst}"
  315. # rename() function will
  316. # rename all the files
  317. os.rename(src, dst)
  318. elif filename == filename_36:
  319. dst =f""+sigla+"_36"+".jpg"
  320. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  321. dst =f"{folder}/{dst}"
  322. # rename() function will
  323. # rename all the files
  324. os.rename(src, dst)
  325. elif filename == filename_37:
  326. dst =f""+sigla+"_37"+".jpg"
  327. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  328. dst =f"{folder}/{dst}"
  329. # rename() function will
  330. # rename all the files
  331. os.rename(src, dst)
  332. elif filename == filename_38:
  333. dst =f""+sigla+"_38"+".jpg"
  334. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  335. dst =f"{folder}/{dst}"
  336. # rename() function will
  337. # rename all the files
  338. os.rename(src, dst)
  339. elif filename == filename_39 :
  340. dst =f""+sigla+"_39"+".jpg"
  341. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  342. dst =f"{folder}/{dst}"
  343. # rename() function will
  344. # rename all the files
  345. os.rename(src, dst)
  346. elif filename == filename_40 :
  347. dst =f""+sigla+"_40"+".jpg"
  348. src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  349. dst =f"{folder}/{dst}"
  350. # rename() function will
  351. # rename all the files
  352. os.rename(src, dst)
  353. # else :
  354. # dst =f""+filename+"_NO_SIGLA"+".jpg"
  355. # src =f"{folder}/{filename}" # foldername/filename, if .py file is outside folder
  356. # dst =f"{folder}/{dst}"
  357. # # rename() function will
  358. # # rename all the files
  359. # os.rename(src, dst)