FUNZIONAAAAAAAAAA!!!!!

This commit is contained in:
2020-03-25 15:18:51 +01:00
parent d06cb0c7c4
commit d9bea99092
3 changed files with 37 additions and 18 deletions

View File

@@ -4,7 +4,7 @@
"lastUsed": "defaults.json",
"configurationPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/bananaSPLIT/conf/",
"INworkPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/TestFiles",
"OUTworkPath": "D:/Emanuele/Documenti/workspace/bananaSPLIT/TestFiles",
"OUTworkPath": "H:/",
"fileList": [
"GUARDIAN 1993.txt",
"GUARDIAN 1996.txt",
@@ -29,11 +29,11 @@
]
},
"docStruct": {
"language": "Italiano",
"language": "English",
"docSep": "\\s*Copyright [(0-9)]+",
"dateFormat": "{month} {day:d}, {year:d}{}",
"outPrefix": "abc",
"outSuffix": "def",
"outPrefix": "PRE",
"outSuffix": "SUF",
"outExt": ".txt",
"outDateType": "jpn",
"outNameFormat": "",
@@ -43,7 +43,7 @@
"numberPos": 1,
"datePos": 2,
"titlePos": 3,
"maxTitleLen": 12,
"maxTitleLen": 10,
"outNameSep": "+",
"customSep": "=",
"dateFormats": {
@@ -53,14 +53,14 @@
}
},
"settings": {
"encoding": "utf-8",
"encoding": "ansi",
"monthPosition": 0,
"getNewsPaperName": true,
"nameNotFoundStr": "ND",
"includeTitle": true,
"removeDuplicates": true,
"showSkipped": true,
"showRemovedDuplicates": false,
"showRemovedDuplicates": true,
"loadTXT": true,
"loadDOCX": false,
"removeOldFiles": true,

View File

@@ -415,9 +415,11 @@ class bananaSelezOut(PyQt5.QtWidgets.QWidget):
def splitta(self):
# costruisco il dizionario di configurazione
prefile = self.conf.inUse
splconf = copy.deepcopy(self.conf.dump())
lang = copy.deepcopy(self.conf.use('languageconf.json').getParam(splconf['docStruct']['language']))
splconf['docStruct']['language'] = lang
self.conf.use(prefile)
#formato nome in uscita
nametemp=[]
@@ -438,9 +440,14 @@ class bananaSelezOut(PyQt5.QtWidgets.QWidget):
# costruisco i thread
tDict={}
for f in splconf['paths']['fileList']:
splconf['name']=f
tDict[f] = bananaSPLITTER(fileParams=copy.deepcopy(splconf), logger=self.log)
try:
for f in splconf['paths']['fileList']:
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
@@ -473,9 +480,12 @@ class bananaSplitterInterface(PyQt5.QtWidgets.QWidget):
#############################################################
####################### MAIN ################################
#############################################################
def except_hook(cls, exception, traceback):
sys.__excepthook__(cls, exception, traceback)
if __name__ == '__main__':
app = PyQt5.QtWidgets.QApplication(sys.argv)
sys.excepthook = except_hook
window = bananaMain()
window.resize(window.sizeHint().width(), window.size().height())
window.show()

View File

@@ -7,15 +7,15 @@ from PyQt5.QtCore import QThread
from PyQt5.Qt import pyqtSignal
from slugify import slugify
import time, parse, re, copy, os, threading
import time, parse, re, copy, os,json
import traceback
class bananaSPLITTER(QThread):
sendStatus = pyqtSignal(str)
def __init__(self, fileParams=None, logger=None):
threading.Thread.__init__(self)
QThread.__init__(self)
self.fileParams = fileParams
self.log = logger
self.rawFile = None
@@ -23,6 +23,7 @@ class bananaSPLITTER(QThread):
self.contentList = list()
self.bodyCounter=0
self.duplicateNumber=0
#self.log.debug(f"Configurazione: \n {json.dumps(fileParams, indent=2)}")
if fileParams is not None:
self.log.info("Sto operando sul file: {}..".format(self.fileParams['name']))
self.paths = self.fileParams['paths']
@@ -74,8 +75,9 @@ class bananaSPLITTER(QThread):
.format(self.fileParams['name'],ee))
except FileExistsError as fe:
self.log.critical(fe)
except BaseException as ee:
self.log.warning(ee)
except Exception as ee:
traceback.print_exc()
self.log.warn(ee)
pass
def openFile(self):
@@ -246,7 +248,7 @@ class bananaSPLITTER(QThread):
for ff in self.contentList:
try:
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),\
docnum=outFileCounter,\
papername=ff['newsPaperName'].strip(),\
@@ -260,8 +262,13 @@ class bananaSPLITTER(QThread):
except IOError as e:
self.log.error("Qualcosa e\' andato storto, non riesco a scrivere il file: {}".format(e))
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:
raise BaseException("Ho salvato meno file rispetto a quelli trovati!")
self.log.error("Ho salvato meno file rispetto a quelli trovati!")
pass
def saveBody(self):
@@ -270,13 +277,15 @@ class bananaSPLITTER(QThread):
os.chdir(self.outPath)
try:
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])
out=open('{0}'.format(fName),'wb')
out.write(fileContent.encode(self.settings['encoding']))
out.close()
except IOError as 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