123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import xml.etree.ElementTree as Xet
- from typing import Dict, Any
- import pandas as pd
- import os
- import csv
- from xml.dom import minidom
- import sys
- import re
- xml_file_name = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/BiblioDatini.xml'
- tree = Xet.parse(xml_file_name)
- root = tree.getroot()
- biblio = root.findall("Biblio")
- Datini_data = open('Datini_Data.csv', 'w')
- csvwriter = csv.writer(Datini_data)
- elemList = []
- xmlTree = Xet.parse(xml_file_name)
- for elem in root.iter():
- elemList.append(elem.tag)
- elemList = list(set(elemList))
- elemList.remove("dataroot")
- elemList.remove("Biblio")
- param = elemList
- csvwriter.writerow(param)
- #param = ["recno", "titolo", "descrizione", "segnatura", "sigla"]
- def cell(p, arr):
- if arr.find(p) is None:
- res = " "
- else:
- res = arr.find(p).text
- return res
- for scheda in biblio:
- aut = []
- for par in param:
- if par == "star_note":
- if scheda.find(".//star_note") is None:
- r = " "
- else:
- r = "True"
- else:
- r = cell(par, scheda)
- aut.append(r)
- csvwriter.writerow(aut)
- Datini_data.close()
|