Compare commits
4 Commits
ccc06bc5f1
...
b6000c49fd
| Author | SHA1 | Date | |
|---|---|---|---|
| b6000c49fd | |||
| 851dcf103d | |||
| 4118ed82c3 | |||
| 435bb144ab |
12012
TestFiles/GUARDIAN 1989.txt
Normal file
12012
TestFiles/GUARDIAN 1989.txt
Normal file
File diff suppressed because it is too large
Load Diff
13811
TestFiles/GUARDIAN 1993.txt
Normal file
13811
TestFiles/GUARDIAN 1993.txt
Normal file
File diff suppressed because it is too large
Load Diff
22792
TestFiles/NYT 1990.txt
Normal file
22792
TestFiles/NYT 1990.txt
Normal file
File diff suppressed because it is too large
Load Diff
23149
TestFiles/NYT 1994.txt
Normal file
23149
TestFiles/NYT 1994.txt
Normal file
File diff suppressed because it is too large
Load Diff
30024
TestFiles/NYT 1997.txt
Normal file
30024
TestFiles/NYT 1997.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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,11 +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
|
||||||
@@ -49,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()
|
||||||
@@ -79,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
|
||||||
@@ -96,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()
|
||||||
@@ -118,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
|
||||||
@@ -155,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
|
||||||
@@ -178,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
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
"logTimeFormat": "%m-%d %H:%M:%S"
|
"logTimeFormat": "%m-%d %H:%M:%S"
|
||||||
},
|
},
|
||||||
"splitter": {
|
"splitter": {
|
||||||
|
"name": "",
|
||||||
"paths": {
|
"paths": {
|
||||||
"INworkPath": "D:\\Test\\",
|
"INworkPath": "D:\\Emanuele\\Documenti\\workspace\\bananaSPLIT\\TestFiles\\",
|
||||||
"OUTworkPath": "D:\\Test\\Separati\\",
|
"OUTworkPath": "D:\\Test\\Separati\\",
|
||||||
"OUTnameFormat": "TEST_{docnum}_{year:04d}{month:02d}{day:02d}_{title}.txt"
|
"OUTnameFormat": "TEST_{docnum}_{year:04d}{month:02d}{day:02d}_{title}.txt"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,8 +6,9 @@
|
|||||||
"logTimeFormat": "%m-%d %H:%M:%S"
|
"logTimeFormat": "%m-%d %H:%M:%S"
|
||||||
},
|
},
|
||||||
"splitter": {
|
"splitter": {
|
||||||
|
"name": "",
|
||||||
"paths": {
|
"paths": {
|
||||||
"INworkPath": "D:\\Test\\",
|
"INworkPath": "D:\\Emanuele\\Documenti\\workspace\\bananaSPLIT\\TestFiles\\",
|
||||||
"OUTworkPath": "D:\\Test\\Separati\\",
|
"OUTworkPath": "D:\\Test\\Separati\\",
|
||||||
"OUTnameFormat": "TEST_{docnum}_{year:04d}{month:02d}{day:02d}_{title}.txt"
|
"OUTnameFormat": "TEST_{docnum}_{year:04d}{month:02d}{day:02d}_{title}.txt"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,11 +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()
|
||||||
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