Il test lancia correttamente i moduli ma siamo tornati agli errori di
parsing, debug necessario...
This commit is contained in:
@@ -25,7 +25,7 @@ class bananaCONF(object):
|
|||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
self.log.info("Carico i file di configurazione")
|
self.log.info("Carico i file di configurazione")
|
||||||
self.fileList = glob.glob(self.workdir+"\\*.json")
|
self.fileList = glob.glob(r"*.json")
|
||||||
if len(self.fileList) > 0:
|
if len(self.fileList) > 0:
|
||||||
for f in self.fileList:
|
for f in self.fileList:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ Created on 2 nov 2019
|
|||||||
@author: Emanuele Trabattoni
|
@author: Emanuele Trabattoni
|
||||||
'''
|
'''
|
||||||
from libfancylogger import fancyLogger
|
from libfancylogger import fancyLogger
|
||||||
import threading, time, parse, re, copy, slugify, os
|
from slugify.slugify import slugify
|
||||||
|
import threading, time, parse, re, copy, os
|
||||||
|
|
||||||
class bananaSPLITTER(threading.Thread):
|
class bananaSPLITTER(threading.Thread):
|
||||||
def __init__(self, fileParams=None, logger=None):
|
def __init__(self, fileParams=None, logger=None):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
self.fileParams = fileParams
|
self.fileParams = fileParams
|
||||||
self.log = logger
|
self.log = logger
|
||||||
self.rawFile = None
|
self.rawFile = None
|
||||||
@@ -48,7 +50,7 @@ class bananaSPLITTER(threading.Thread):
|
|||||||
|
|
||||||
def openFile(self):
|
def openFile(self):
|
||||||
try:
|
try:
|
||||||
self.info("Carico il contenuto..")
|
self.log.info("Carico il contenuto..")
|
||||||
fp = open(self.fileParams['name'], mode='r', encoding=self.settings['encoding'])
|
fp = open(self.fileParams['name'], mode='r', encoding=self.settings['encoding'])
|
||||||
self.rawFile = fp.readlines()
|
self.rawFile = fp.readlines()
|
||||||
fp.close()
|
fp.close()
|
||||||
@@ -78,6 +80,7 @@ class bananaSPLITTER(threading.Thread):
|
|||||||
docNumber = 0
|
docNumber = 0
|
||||||
docSkipped = 0
|
docSkipped = 0
|
||||||
docDate = {}
|
docDate = {}
|
||||||
|
title = ''
|
||||||
prevLine = ''
|
prevLine = ''
|
||||||
newsPaperName = ''
|
newsPaperName = ''
|
||||||
titleBegin = False
|
titleBegin = False
|
||||||
@@ -95,14 +98,14 @@ class bananaSPLITTER(threading.Thread):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if self.settings["showSkipped"]:
|
if self.settings["showSkipped"]:
|
||||||
self.log.warning("Il conto dei documenti non torna! LexisNexis \
|
self.log.warn("Il conto dei documenti non torna! LexisNexis \
|
||||||
ne ha saltato qualcuno!\nPrecedente:{0}-Attuale:{1}".format(docNumber,nn["current"]))
|
ne ha saltato qualcuno!\nPrecedente:{0}-Attuale:{1}".format(docNumber,nn["current"]))
|
||||||
docSkipped+=1
|
docSkipped+=1
|
||||||
docNumber = nn["current"]
|
docNumber = nn["current"]
|
||||||
except:
|
except:
|
||||||
pass #non segnalare eccezione se il parse fallisce
|
pass #non segnalare eccezione se il parse fallisce
|
||||||
# ricerco la data
|
# ricerco la data
|
||||||
if (lineWords[self.settings['monthPosition']]).capitalize() in self.docParams['dateWords']:
|
if (lineWords[self.settings['monthPosition']]).capitalize() in self.docStruct['dateWords']:
|
||||||
try:
|
try:
|
||||||
docDate=parse.parse(self.docParams['dateFormat'],l).named
|
docDate=parse.parse(self.docParams['dateFormat'],l).named
|
||||||
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
||||||
@@ -117,12 +120,12 @@ class bananaSPLITTER(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
newsPaperName = self.settings['nameNotFoundStr']
|
newsPaperName = self.settings['nameNotFoundStr']
|
||||||
except:
|
except:
|
||||||
self.log.warning("E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
self.log.warn("E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
||||||
controlla i file di uscita! \n\t[{}]".format(prevLine.strip()))
|
controlla i file di uscita! \n\t[{}]".format(prevLine.strip()))
|
||||||
else:
|
else:
|
||||||
newsPaperName = self.settings['nameNotFoundStr']
|
newsPaperName = self.settings['nameNotFoundStr']
|
||||||
except:
|
except:
|
||||||
self.log.warning("Ho trovato una riga ambigua.. potrebbe essere una data ma non so: \n\t[{}]". format(l.strip('\r\n')))
|
self.log.warn("Ho trovato una riga ambigua.. potrebbe essere una data ma non so: \n\t[{}]". format(l.strip('\r\n')))
|
||||||
pass
|
pass
|
||||||
elif lineWords[0] in self.docStruct['headWords']:
|
elif lineWords[0] in self.docStruct['headWords']:
|
||||||
#cambio stato e inizializzo un nuovo documento da riempire
|
#cambio stato e inizializzo un nuovo documento da riempire
|
||||||
@@ -154,7 +157,7 @@ class bananaSPLITTER(threading.Thread):
|
|||||||
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 docSep.match(l) is not None: #controlla se ci sono articoli che non hanno le parole chiave finali
|
||||||
self.log.warning("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
|
||||||
@@ -177,7 +180,7 @@ class bananaSPLITTER(threading.Thread):
|
|||||||
#ricerca terminata, espongo i risultati
|
#ricerca terminata, espongo i risultati
|
||||||
self.log.info("Nel file ho trovato {0} articoli..".format(self.bodyCounter))
|
self.log.info("Nel file ho trovato {0} articoli..".format(self.bodyCounter))
|
||||||
if docSkipped > 0:
|
if docSkipped > 0:
|
||||||
self.log.warning("Attentione, LexisNexis ne ha saltati {} !!!".format(docSkipped))
|
self.log.warn("Attentione, LexisNexis ne ha saltati {} !!!".format(docSkipped))
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,19 @@ from libsplit import bananaSPLITTER
|
|||||||
from libconfload import bananaCONF
|
from libconfload import bananaCONF
|
||||||
from libfancylogger import fancyLogger
|
from libfancylogger import fancyLogger
|
||||||
|
|
||||||
print(os.getcwd())
|
print("CWD-> "+os.getcwd())
|
||||||
logger = fancyLogger(fileLog = False)
|
logger = fancyLogger(fileLog = False)
|
||||||
confl = bananaCONF(workdir=r"./libbananasplit", logger=logger)
|
confl = bananaCONF(workdir=r"./libbananasplit", logger=logger)
|
||||||
splconf = confl.use("testEN")
|
confl.open()
|
||||||
splconf["name"] = "GUARDIAN.txt"
|
|
||||||
splitter = bananaSPLITTER()
|
confl.use("testEN.json")
|
||||||
|
splconf = confl.getParams("splitter")
|
||||||
|
splconf["name"] = splconf["paths"]["INworkPath"]+"GUARDIAN 1989.txt"
|
||||||
|
splitter = bananaSPLITTER(fileParams=splconf, logger=logger)
|
||||||
|
splitter.start()
|
||||||
|
splitter.join()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user