123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import os
- import xml.etree.ElementTree as Xet
- import re
- from xml.etree import ElementTree
- import csv
- nolemmi = []
- basepath_nolemmi = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/DatiniXML_incompleto'
- for entry in os.listdir(basepath_nolemmi):
- if os.path.isfile(os.path.join(basepath_nolemmi, entry)):
- nn = entry.split('.')[1].lstrip().split(' ')[0]
- if nn != '':
- nolemmi.append([nn, entry])
- lemmi = []
- basepath_lemmi = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/lemmi'
- for entry in os.listdir(basepath_lemmi):
- if os.path.isfile(os.path.join(basepath_lemmi, entry)):
- ll = entry.split('.')[1].lstrip().split(' ')[0]
- if ll != '':
- lemmi.append([ll, entry])
- gat = []
- basepath_gat = '/Users/alessiaspadi/Documents/RESTORE/temp_ovi/xmlgat'
- for entry in os.listdir(basepath_gat):
- if os.path.isfile(os.path.join(basepath_gat, entry)):
- gg = entry.split('.')[1].lstrip().split(' ')[0]
- if gg != '':
- gat.append([gg, entry])
- xmlparse = Xet.parse('/Users/alessiaspadi/Documents/RESTORE/temp_ovi/BiblioDatini.xml')
- root = xmlparse.getroot()
- biblio = root.findall("Biblio")
- sigle = []
- for bib in biblio:
- sigla = bib.find("sigla")
- sigle.append(sigla.text.lower())
- print (nolemmi)
- print (lemmi)
- print (gat)
- print (sigle)
- OVI_data = open('OVI_Data.csv', 'w')
- csvwriter = csv.writer(OVI_data)
- params = ["BiblioDatini", "nolemmi", "lemmi", "xmlgat"]
- csvwriter.writerow(params)
- for sigla in sigle:
- row = [sigla]
- no_lemma = " "
- lemma = " "
- gatto = " "
- for x in range(len(nolemmi)):
- if sigla in nolemmi[x][0]:
- no_lemma = nolemmi[x][1]
- row.append(no_lemma)
- for x in range(len(lemmi)):
- if sigla == lemmi[x][0]:
- lemma = lemmi[x][1]
- row.append(lemma)
- for x in range(len(gat)):
- if sigla == gat[x][0]:
- gatto = gat[x][1]
- row.append(gatto)
- csvwriter.writerow(row)
- OVI_data.close()
|