prima della prima prova della nuova versione
This commit is contained in:
@@ -13,7 +13,7 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
txt=docx2txt.process(f)
|
txt=docx2txt.process(f)
|
||||||
with open(f.replace('.docx', '.txt'), 'w') as fp:
|
with open(f.replace('.docx', '.txt'), 'w') as fp:
|
||||||
fp.write(txt.replace('\r\n','\n'))
|
fp.write(txt)
|
||||||
fp.close()
|
fp.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|||||||
@@ -120,46 +120,21 @@ class bananaSPLITTER(QRunnable):
|
|||||||
title = ''
|
title = ''
|
||||||
prevLine = ''
|
prevLine = ''
|
||||||
newsPaperName = ''
|
newsPaperName = ''
|
||||||
titleBegin = False
|
titleBegin = True
|
||||||
|
newsName = False
|
||||||
tempBody = list()
|
tempBody = list()
|
||||||
docSep=re.compile(self.docStruct['docSep'])
|
|
||||||
|
|
||||||
for l in self.rawFile: #per ogni linea del file
|
for l in self.rawFile: #per ogni linea del file
|
||||||
lineWords = l.lstrip().split(' ') #dividi la riga in parole
|
lineWords = l.lstrip().split(' ') #dividi la riga in parole
|
||||||
if self.status == 'first':
|
if self.status == 'first':
|
||||||
#prendo il numero di documento per vedere se ci sono buchi
|
|
||||||
try:
|
try:
|
||||||
try:
|
|
||||||
nn = parse.parse("{current:d} Of {total} Documents",l.strip().capitalize()).named
|
|
||||||
if nn["current"]-docNumber==1:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if self.settings["showSkipped"]:
|
|
||||||
self.log.warn("Il conto dei documenti non torna! LexisNexis ne ha saltato qualcuno!\n Precedente:{0}-Attuale:{1}".format(docNumber,nn["current"]))
|
|
||||||
docSkipped+=1
|
|
||||||
docNumber = nn["current"]
|
|
||||||
except:
|
|
||||||
pass #non segnalare eccezione se il parse fallisce
|
|
||||||
# ricerco la data
|
# ricerco la data
|
||||||
if (lineWords[self.settings['monthPosition']]).capitalize() in self.docStruct['language']['dateWords']:
|
if (lineWords[self.settings['monthPosition']]).capitalize() in self.docStruct['language']['dateWords']:
|
||||||
try:
|
try:
|
||||||
docDate=parse.parse(self.docStruct['dateFormat'],l).named
|
docDate=parse.parse(self.docStruct['dateFormat'],l).named
|
||||||
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
||||||
docDate['month']=self.docStruct['language']['dateWords'].index(docDate['month'])+1
|
docDate['month']=self.docStruct['language']['dateWords'].index(docDate['month'])+1
|
||||||
title = ''
|
|
||||||
titleBegin=True
|
|
||||||
# dopo la data inizia il titolo, ma prima si cerca il nome del giornale
|
# dopo la data inizia il titolo, ma prima si cerca il nome del giornale
|
||||||
if self.settings['getNewsPaperName']:
|
|
||||||
try:
|
|
||||||
if prevLine.split(' ')[0].strip().isalpha():
|
|
||||||
newsPaperName = prevLine.strip()
|
|
||||||
else:
|
|
||||||
newsPaperName = self.settings['nameNotFoundStr']
|
|
||||||
except:
|
|
||||||
self.log.warn("E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
|
||||||
controlla i file di uscita! [{}]".format(prevLine.strip()))
|
|
||||||
else:
|
|
||||||
newsPaperName = self.settings['nameNotFoundStr']
|
|
||||||
except:
|
except:
|
||||||
self.log.warn("Ho trovato una riga ambigua.. potrebbe essere una data ma non so: [{}]". format(l.strip('\r\n')))
|
self.log.warn("Ho trovato una riga ambigua.. potrebbe essere una data ma non so: [{}]". format(l.strip('\r\n')))
|
||||||
pass
|
pass
|
||||||
@@ -171,18 +146,37 @@ class bananaSPLITTER(QRunnable):
|
|||||||
newDoc['date']=docDate
|
newDoc['date']=docDate
|
||||||
newDoc['newsPaperName'] = newsPaperName
|
newDoc['newsPaperName'] = newsPaperName
|
||||||
titleBegin = False
|
titleBegin = False
|
||||||
|
newsName = False
|
||||||
else:
|
else:
|
||||||
if titleBegin:
|
if titleBegin:
|
||||||
title += l.strip().capitalize()
|
title += l.strip().capitalize()
|
||||||
|
titleBegin = False
|
||||||
|
newsName = True
|
||||||
|
elif newsName:
|
||||||
|
if self.settings['getNewsPaperName']:
|
||||||
|
try:
|
||||||
|
if l.strip().isalpha():
|
||||||
|
newsPaperName = l.strip()
|
||||||
|
else:
|
||||||
|
newsPaperName = self.settings['nameNotFoundStr']
|
||||||
|
except:
|
||||||
|
self.log.warn("E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
||||||
|
controlla i file di uscita! [{}]".format(l.strip()))
|
||||||
|
else:
|
||||||
|
newsPaperName = self.settings['nameNotFoundStr']
|
||||||
|
newsName = False
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
self.log.error("Errore inaspettato, contatta il tuo sviluppatore di fiducia!")
|
self.log.error("Errore inaspettato, contatta il tuo sviluppatore di fiducia!")
|
||||||
pass
|
pass
|
||||||
elif self.status == 'head':
|
elif self.status == 'head':
|
||||||
tempContent = list()
|
tempContent = list()
|
||||||
|
#doppio check per trovare línizio del corpo documento
|
||||||
|
if re.match(self.docStruct['beginOfDocument'],l,re.i):
|
||||||
|
self.status='body'
|
||||||
if lineWords[0] not in self.docStruct['language']['headWords']: #se la prima parola non e' tra quelle di inizio
|
if lineWords[0] not in self.docStruct['language']['headWords']: #se la prima parola non e' tra quelle di inizio
|
||||||
tempBody.append(l) # vuol dire che ho trovato l'articolo e aggiungo la prima riga al contenuto del documento
|
tempBody.append(l) # vuol dire che ho trovato l'articolo e aggiungo la prima riga al contenuto del documento
|
||||||
self.status = 'body'
|
self.status = 'body'
|
||||||
pass
|
|
||||||
elif self.status == 'body':
|
elif self.status == 'body':
|
||||||
if not lineWords[0] in self.docStruct['language']['tailWords']: #se la prima parola non e' tra quelle di fine
|
if not lineWords[0] in self.docStruct['language']['tailWords']: #se la prima parola non e' tra quelle di fine
|
||||||
if self.settings['delLF']:
|
if self.settings['delLF']:
|
||||||
@@ -192,14 +186,14 @@ class bananaSPLITTER(QRunnable):
|
|||||||
else:
|
else:
|
||||||
self.status = 'tail'
|
self.status = 'tail'
|
||||||
anomaly = False
|
anomaly = False
|
||||||
if docSep.match(l) is not None: #controlla se ci sono articoli che non hanno le parole chiave finali
|
if re.match(self.docStruct['endOfDocument'],l) is not None: #controlla se ci sono articoli che non hanno le parole chiave finali
|
||||||
self.log.warn("Ho individuato una separatore valido prima che si chiusesse l'articolo precedente, controlla i tuoi file in uscita!\n\
|
self.log.warn("Ho individuato una separatore valido prima che si chiusesse l'articolo precedente, controlla i tuoi file in uscita!\n\
|
||||||
L'errore dovrebbe essere intorno all'articolo {} ma non sono sicuro! \n\t\t[{}]".format(docNumber, l.strip()))
|
L'errore dovrebbe essere intorno all'articolo {} ma non sono sicuro! \n\t\t[{}]".format(docNumber, l.strip()))
|
||||||
self.status = 'tail'
|
self.status = 'tail'
|
||||||
anomaly = True
|
anomaly = True
|
||||||
pass
|
pass
|
||||||
elif self.status == 'tail':
|
elif self.status == 'tail':
|
||||||
if docSep.match(l) is not None or anomaly:
|
if re.match(self.docStruct['endOfDocument'],l) is not None or anomaly:
|
||||||
self.status = 'first'
|
self.status = 'first'
|
||||||
anomaly = False
|
anomaly = False
|
||||||
if self.settings['delWordBreak']:
|
if self.settings['delWordBreak']:
|
||||||
|
|||||||
Reference in New Issue
Block a user