confrontoDatiOVI.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import os
  2. import xml.etree.ElementTree as Xet
  3. import re
  4. from xml.etree import ElementTree
  5. import csv
  6. nolemmi = []
  7. basepath_nolemmi = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/DatiniXML_incompleto'
  8. for entry in os.listdir(basepath_nolemmi):
  9. if os.path.isfile(os.path.join(basepath_nolemmi, entry)):
  10. nn = entry.split('.')[1].lstrip().split(' ')[0]
  11. if nn != '':
  12. nolemmi.append([nn, entry])
  13. lemmi = []
  14. basepath_lemmi = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/lemmi'
  15. for entry in os.listdir(basepath_lemmi):
  16. if os.path.isfile(os.path.join(basepath_lemmi, entry)):
  17. ll = entry.split('.')[1].lstrip().split(' ')[0]
  18. if ll != '':
  19. lemmi.append([ll, entry])
  20. gat = []
  21. basepath_gat = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/xmlgat'
  22. for entry in os.listdir(basepath_gat):
  23. if os.path.isfile(os.path.join(basepath_gat, entry)):
  24. gg = entry.split('.')[1].lstrip().split(' ')[0]
  25. if gg != '':
  26. gat.append([gg, entry])
  27. xmlparse = Xet.parse('/Users/alessiaspadi/Documents/RESTORE/temp_ovi/BiblioDatini.xml')
  28. root = xmlparse.getroot()
  29. biblio = root.findall("Biblio")
  30. sigle = []
  31. for bib in biblio:
  32. sigla = bib.find("sigla")
  33. sigle.append(sigla.text.lower())
  34. print (nolemmi)
  35. print (lemmi)
  36. print (gat)
  37. print (sigle)
  38. OVI_data = open('OVI_Data.csv', 'w')
  39. csvwriter = csv.writer(OVI_data)
  40. params = ["BiblioDatini", "nolemmi", "lemmi", "xmlgat"]
  41. csvwriter.writerow(params)
  42. for sigla in sigle:
  43. row = [sigla]
  44. no_lemma = " "
  45. lemma = " "
  46. gatto = " "
  47. for x in range(len(nolemmi)):
  48. if sigla in nolemmi[x][0]:
  49. no_lemma = nolemmi[x][1]
  50. row.append(no_lemma)
  51. for x in range(len(lemmi)):
  52. if sigla == lemmi[x][0]:
  53. lemma = lemmi[x][1]
  54. row.append(lemma)
  55. for x in range(len(gat)):
  56. if sigla == gat[x][0]:
  57. gatto = gat[x][1]
  58. row.append(gatto)
  59. csvwriter.writerow(row)
  60. OVI_data.close()