export_xmlgat_files_to_evt.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # %%
  2. import xmlgat_to_EVT_parser as evtPar
  3. import os
  4. import xml.etree.ElementTree as ET
  5. basedir = '../../Data/'
  6. baseindir = basedir + 'DallOVI/datiniXML/xmlgat/'
  7. baseoutdir = basedir + 'DallOVI/datiniXML/xmlevt/lettere/'
  8. # %%
  9. for file in os.listdir(baseindir):
  10. try:
  11. local_filecode = file.replace('xmlgat.', '').replace('.xml', '')
  12. local_string = evtPar.newProcessFile(local_filecode)
  13. new_LocalString = evtPar.letterTemplateString.replace('<letterBody />', local_string)
  14. with open(baseoutdir + local_filecode + '.xml', 'w') as f1:
  15. f1.write(new_LocalString)
  16. except ET.ParseError:
  17. print("ParseError - " + file)
  18. except KeyError:
  19. print("KeyError - " + file)
  20. except IndexError:
  21. print("IndexError - " + file)
  22. print('DONE!')
  23. # %%
  24. # NOTA TEMPORANEA: allo stato attuale (16/02/2022), la grande maggioranza dei files vengono esportati con successo.
  25. # Avendo dato un'occhiata a campione, gli output sembrano buoni -- dovrebbero essere 'mangiabili' da EVT.
  26. # Ci sono però un certo numero di errori nel processare i files, la maggior parte errori di parsing di ElementTree probabilmente dovuti a stranezze nei file di input, ma alcuni paiono essere bug
  27. # ---
  28. # DA INVESTIGARE!
  29. # ParseError - xmlgat.j34.xml
  30. # KeyError - xmlgat.x03.xml
  31. # ParseError - xmlgat.j92.xml
  32. # ParseError - xmlgat.j37.xml
  33. # IndexError - xmlgat.k43.xml
  34. # ParseError - xmlgat.j95.xml
  35. # ParseError - xmlgat.k01.xml
  36. # ParseError - xmlgat.k00.xml
  37. # ParseError - xmlgat.j82.xml
  38. # ParseError - xmlgat.j62.xml
  39. # ParseError - xmlgat.j85.xml
  40. # ParseError - xmlgat.28d.xml
  41. # ParseError - xmlgat.c13.xml
  42. # ParseError - xmlgat.j88.xml
  43. # ParseError - xmlgat.j98.xml
  44. # ParseError - xmlgat.j33.xml
  45. # ParseError - xmlgat.j74.xml
  46. # IndexError - xmlgat.c33.xml
  47. # ParseError - xmlgat.j99.xml