FUNZIONAAAAAAAAAA!!!!!
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"lastUsed": "defaults.json",
|
"lastUsed": "defaults.json",
|
||||||
"configurationPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/bananaSPLIT/conf/",
|
"configurationPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/bananaSPLIT/conf/",
|
||||||
"INworkPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/TestFiles",
|
"INworkPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/TestFiles",
|
||||||
"OUTworkPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/TestFiles",
|
"OUTworkPath": "H:/",
|
||||||
"fileList": [
|
"fileList": [
|
||||||
"GUARDIAN 1993.txt",
|
"GUARDIAN 1993.txt",
|
||||||
"GUARDIAN 1996.txt",
|
"GUARDIAN 1996.txt",
|
||||||
@@ -29,11 +29,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"docStruct": {
|
"docStruct": {
|
||||||
"language": "Italiano",
|
"language": "English",
|
||||||
"docSep": "\\s*Copyright [(0-9)]+",
|
"docSep": "\\s*Copyright [(0-9)]+",
|
||||||
"dateFormat": "{month} {day:d}, {year:d}{}",
|
"dateFormat": "{month} {day:d}, {year:d}{}",
|
||||||
"outPrefix": "abc",
|
"outPrefix": "PRE",
|
||||||
"outSuffix": "def",
|
"outSuffix": "SUF",
|
||||||
"outExt": ".txt",
|
"outExt": ".txt",
|
||||||
"outDateType": "jpn",
|
"outDateType": "jpn",
|
||||||
"outNameFormat": "",
|
"outNameFormat": "",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"numberPos": 1,
|
"numberPos": 1,
|
||||||
"datePos": 2,
|
"datePos": 2,
|
||||||
"titlePos": 3,
|
"titlePos": 3,
|
||||||
"maxTitleLen": 12,
|
"maxTitleLen": 10,
|
||||||
"outNameSep": "+",
|
"outNameSep": "+",
|
||||||
"customSep": "=",
|
"customSep": "=",
|
||||||
"dateFormats": {
|
"dateFormats": {
|
||||||
@@ -53,14 +53,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"encoding": "utf-8",
|
"encoding": "ansi",
|
||||||
"monthPosition": 0,
|
"monthPosition": 0,
|
||||||
"getNewsPaperName": true,
|
"getNewsPaperName": true,
|
||||||
"nameNotFoundStr": "ND",
|
"nameNotFoundStr": "ND",
|
||||||
"includeTitle": true,
|
"includeTitle": true,
|
||||||
"removeDuplicates": true,
|
"removeDuplicates": true,
|
||||||
"showSkipped": true,
|
"showSkipped": true,
|
||||||
"showRemovedDuplicates": false,
|
"showRemovedDuplicates": true,
|
||||||
"loadTXT": true,
|
"loadTXT": true,
|
||||||
"loadDOCX": false,
|
"loadDOCX": false,
|
||||||
"removeOldFiles": true,
|
"removeOldFiles": true,
|
||||||
|
|||||||
@@ -415,9 +415,11 @@ class bananaSelezOut(PyQt5.QtWidgets.QWidget):
|
|||||||
|
|
||||||
def splitta(self):
|
def splitta(self):
|
||||||
# costruisco il dizionario di configurazione
|
# costruisco il dizionario di configurazione
|
||||||
|
prefile = self.conf.inUse
|
||||||
splconf = copy.deepcopy(self.conf.dump())
|
splconf = copy.deepcopy(self.conf.dump())
|
||||||
lang = copy.deepcopy(self.conf.use('languageconf.json').getParam(splconf['docStruct']['language']))
|
lang = copy.deepcopy(self.conf.use('languageconf.json').getParam(splconf['docStruct']['language']))
|
||||||
splconf['docStruct']['language'] = lang
|
splconf['docStruct']['language'] = lang
|
||||||
|
self.conf.use(prefile)
|
||||||
|
|
||||||
#formato nome in uscita
|
#formato nome in uscita
|
||||||
nametemp=[]
|
nametemp=[]
|
||||||
@@ -438,9 +440,14 @@ class bananaSelezOut(PyQt5.QtWidgets.QWidget):
|
|||||||
|
|
||||||
# costruisco i thread
|
# costruisco i thread
|
||||||
tDict={}
|
tDict={}
|
||||||
for f in splconf['paths']['fileList']:
|
try:
|
||||||
splconf['name']=f
|
for f in splconf['paths']['fileList']:
|
||||||
tDict[f] = bananaSPLITTER(fileParams=copy.deepcopy(splconf), logger=self.log)
|
splconf['name']=f
|
||||||
|
tDict[f] = bananaSPLITTER(fileParams=copy.deepcopy(splconf), logger=self.log)
|
||||||
|
tDict[f].start()
|
||||||
|
tDict[f].wait()
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error(f"Impossibile avviare lo splitter: {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -473,9 +480,12 @@ class bananaSplitterInterface(PyQt5.QtWidgets.QWidget):
|
|||||||
#############################################################
|
#############################################################
|
||||||
####################### MAIN ################################
|
####################### MAIN ################################
|
||||||
#############################################################
|
#############################################################
|
||||||
|
def except_hook(cls, exception, traceback):
|
||||||
|
sys.__excepthook__(cls, exception, traceback)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = PyQt5.QtWidgets.QApplication(sys.argv)
|
app = PyQt5.QtWidgets.QApplication(sys.argv)
|
||||||
|
sys.excepthook = except_hook
|
||||||
window = bananaMain()
|
window = bananaMain()
|
||||||
window.resize(window.sizeHint().width(), window.size().height())
|
window.resize(window.sizeHint().width(), window.size().height())
|
||||||
window.show()
|
window.show()
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ from PyQt5.QtCore import QThread
|
|||||||
from PyQt5.Qt import pyqtSignal
|
from PyQt5.Qt import pyqtSignal
|
||||||
|
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
import time, parse, re, copy, os, threading
|
import time, parse, re, copy, os,json
|
||||||
|
import traceback
|
||||||
|
|
||||||
class bananaSPLITTER(QThread):
|
class bananaSPLITTER(QThread):
|
||||||
|
|
||||||
sendStatus = pyqtSignal(str)
|
sendStatus = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, fileParams=None, logger=None):
|
def __init__(self, fileParams=None, logger=None):
|
||||||
threading.Thread.__init__(self)
|
QThread.__init__(self)
|
||||||
self.fileParams = fileParams
|
self.fileParams = fileParams
|
||||||
self.log = logger
|
self.log = logger
|
||||||
self.rawFile = None
|
self.rawFile = None
|
||||||
@@ -23,6 +23,7 @@ class bananaSPLITTER(QThread):
|
|||||||
self.contentList = list()
|
self.contentList = list()
|
||||||
self.bodyCounter=0
|
self.bodyCounter=0
|
||||||
self.duplicateNumber=0
|
self.duplicateNumber=0
|
||||||
|
#self.log.debug(f"Configurazione: \n {json.dumps(fileParams, indent=2)}")
|
||||||
if fileParams is not None:
|
if fileParams is not None:
|
||||||
self.log.info("Sto operando sul file: {}..".format(self.fileParams['name']))
|
self.log.info("Sto operando sul file: {}..".format(self.fileParams['name']))
|
||||||
self.paths = self.fileParams['paths']
|
self.paths = self.fileParams['paths']
|
||||||
@@ -74,8 +75,9 @@ class bananaSPLITTER(QThread):
|
|||||||
.format(self.fileParams['name'],ee))
|
.format(self.fileParams['name'],ee))
|
||||||
except FileExistsError as fe:
|
except FileExistsError as fe:
|
||||||
self.log.critical(fe)
|
self.log.critical(fe)
|
||||||
except BaseException as ee:
|
except Exception as ee:
|
||||||
self.log.warning(ee)
|
traceback.print_exc()
|
||||||
|
self.log.warn(ee)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def openFile(self):
|
def openFile(self):
|
||||||
@@ -246,7 +248,7 @@ class bananaSPLITTER(QThread):
|
|||||||
for ff in self.contentList:
|
for ff in self.contentList:
|
||||||
try:
|
try:
|
||||||
if ff['duplicate'] == False:
|
if ff['duplicate'] == False:
|
||||||
fName=self.paths['OUTnameFormat'].format(title=slugify(ff['title'][:self.settings['maxTitleLen']]),\
|
fName=self.docStruct['outNameFormat'].format(title=slugify(ff['title'][:self.docStruct['maxTitleLen']]),\
|
||||||
filename=slugify(self.fileName),\
|
filename=slugify(self.fileName),\
|
||||||
docnum=outFileCounter,\
|
docnum=outFileCounter,\
|
||||||
papername=ff['newsPaperName'].strip(),\
|
papername=ff['newsPaperName'].strip(),\
|
||||||
@@ -260,8 +262,13 @@ class bananaSPLITTER(QThread):
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
self.log.error("Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
|
self.log.error("Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
|
||||||
continue
|
continue
|
||||||
|
except KeyError as ke:
|
||||||
|
self.log.error(f"Chiave {ke} non trovata per:{outFileCounter} {ff['title']} ")
|
||||||
|
except Exception as ee:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.log.error(f"Errore generale nel salvataggio: {ee}")
|
||||||
if outFileCounter < self.bodyCounter:
|
if outFileCounter < self.bodyCounter:
|
||||||
raise BaseException("Ho salvato meno file rispetto a quelli trovati!")
|
self.log.error("Ho salvato meno file rispetto a quelli trovati!")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def saveBody(self):
|
def saveBody(self):
|
||||||
@@ -270,13 +277,15 @@ class bananaSPLITTER(QThread):
|
|||||||
os.chdir(self.outPath)
|
os.chdir(self.outPath)
|
||||||
try:
|
try:
|
||||||
fName=slugify(self.fileName)
|
fName=slugify(self.fileName)
|
||||||
fName='BODYFILE_{0}.txt'.format(fName[:self.settings['maxTitleLen']])
|
fName='BODYFILE_{0}.txt'.format(fName[:self.docStruct['maxTitleLen']])
|
||||||
fileContent = os.linesep.join([cc['content'] for cc in self.contentList])
|
fileContent = os.linesep.join([cc['content'] for cc in self.contentList])
|
||||||
out=open('{0}'.format(fName),'wb')
|
out=open('{0}'.format(fName),'wb')
|
||||||
out.write(fileContent.encode(self.settings['encoding']))
|
out.write(fileContent.encode(self.settings['encoding']))
|
||||||
out.close()
|
out.close()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
self.log.error("Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
|
self.log.error("Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
|
||||||
|
except Exception as ee:
|
||||||
|
self.log.error(f"Errore generale nel salvataggio: {ee}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user