Compare commits
11 Commits
master
...
8ec7e5e835
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ec7e5e835 | |||
| 4f05729782 | |||
| d7321a5041 | |||
| a29aa4da91 | |||
| 170959e529 | |||
| 3fa74f6ed9 | |||
| 2f1236449a | |||
|
|
f43ed84d72 | ||
| 4057b31203 | |||
|
|
0ddd8af3bc | ||
| eec006f6c5 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/.DS_Store
|
/.DS_Store
|
||||||
/.project
|
/.project
|
||||||
/.pydevproject
|
/.pydevproject
|
||||||
|
bananaSPLIT/build
|
||||||
BIN
WinBuild/dist/bananaSPLIT.exe
vendored
BIN
WinBuild/dist/bananaSPLIT.exe
vendored
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 79 KiB |
@@ -1,25 +1,94 @@
|
|||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<author></author>
|
<ui version="4.0">
|
||||||
<comment></comment>
|
<class>win_main</class>
|
||||||
<exportmacro></exportmacro>
|
<widget class="QMainWindow" name="win_main">
|
||||||
<class>MainWindow</class>
|
<property name="geometry">
|
||||||
<widget class="QMainWindow" name="MainWindow" >
|
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>697</width>
|
||||||
<height>600</height>
|
<height>454</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenuBar" name="menubar" />
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QWidget" name="centralwidget" />
|
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||||
<widget class="QStatusBar" name="statusbar" />
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>161</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_cartellasorg">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Cartella sorgente</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_cartellasorg">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="horizontalLayoutWidget_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>60</y>
|
||||||
|
<width>161</width>
|
||||||
|
<height>31</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_cartelladest">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>10</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Cartella destinazione</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_cartelladest">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>697</width>
|
||||||
|
<height>21</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<pixmapfunction></pixmapfunction>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
||||||
|
|||||||
32
bananaSPLIT/bananaSPLIT.exe.spec
Normal file
32
bananaSPLIT/bananaSPLIT.exe.spec
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# -*- mode: python -*-
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(['main.py'],
|
||||||
|
pathex=['D:\\Emanuele\\Documenti\\workspace\\bananaSPLIT\\bananaSPLIT'],
|
||||||
|
binaries=[],
|
||||||
|
datas=[('C:\\Users\\Emanuele Trabattoni\\AppData\\Roaming\\Python\\Python37\\site-packages\\text_unidecode\\data.bin', '.\\text_unidecode')],
|
||||||
|
hiddenimports=[],
|
||||||
|
hookspath=[],
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher,
|
||||||
|
noarchive=False)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data,
|
||||||
|
cipher=block_cipher)
|
||||||
|
exe = EXE(pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='bananaSPLIT.exe',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True , icon='banana.ico')
|
||||||
BIN
bananaSPLIT/dist/bananaSPLIT.exe
vendored
Normal file
BIN
bananaSPLIT/dist/bananaSPLIT.exe
vendored
Normal file
Binary file not shown.
@@ -15,26 +15,24 @@ from pprint import pprint
|
|||||||
from glob import glob
|
from glob import glob
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
|
||||||
|
|
||||||
####### VAR GLOBALI #######
|
####### VAR GLOBALI #######
|
||||||
|
|
||||||
####### FUNZIONI GLOBALI #######
|
####### FUNZIONI GLOBALI #######
|
||||||
def printTitle():
|
def printTitle():
|
||||||
print(". . . , \n| | _ | _. _ ._ _ _ -+- _ * \n|/\|(/,|(_.(_)[ | )(/, | (_) *")
|
print(". . . , \n| | _ | _. _ ._ _ _ -+- _ * \n|/\|(/,|(_.(_)[ | )(/, | (_) *")
|
||||||
|
|
||||||
print(Fore.LIGHTYELLOW_EX,\
|
print(Fore.LIGHTYELLOW_EX,\
|
||||||
' _ ___________ _ _____ _____ \n\
|
' _ ___________ _ _____ _____ \n\
|
||||||
| | / ___| ___ \ | |_ _|_ _| \n\
|
| | / ___| ___ \ | |_ _|_ _| \n\
|
||||||
| |__ __ _ _ __ __ _ _ __ __ _\ `--.| |_/ / | | | | | \n\
|
| |__ __ _ _ __ __ _ _ __ __ _\ `--.| |_/ / | | | | | \n\
|
||||||
| \'_ \ / _` | \'_ \ / _` | \'_ \ / _` |`--. \ __/| | | | | | \n\
|
| \'_ \ / _` | \'_ \ / _` | \'_ \ / _` |`--. \ __/| | | | | | \n\
|
||||||
| |_) | (_| | | | | (_| | | | | (_| /\__/ / | | |_____| |_ | | \n\
|
| |_) | (_| | | | | (_| | | | | (_| /\__/ / | | |_____| |_ | | \n\
|
||||||
|_.__/ \__,_|_| |_|\__,_|_| |_|\__,_\____/\_| \_____/\___/ \_/')
|
|_.__/ \__,_|_| |_|\__,_|_| |_|\__,_\____/\_| \_____/\___/ \_/')
|
||||||
|
|
||||||
print ('\t\t\t\t\t\t\tVersione 0.4a\n\n', Style.RESET_ALL)
|
print ('\t\t\t\t\t\t\tVersione 0.4a\n\n', Style.RESET_ALL)
|
||||||
print('Iniziamo!!')
|
print('Iniziamo!!')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#############################################################
|
#############################################################
|
||||||
####################### MAIN ################################
|
####################### MAIN ################################
|
||||||
#############################################################
|
#############################################################
|
||||||
@@ -44,82 +42,86 @@ status={'first':0, 'head':1, 'body':2, 'tail':3}
|
|||||||
s=status['first']
|
s=status['first']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conffiles = glob('*.json')
|
conffiles = glob('*.json')
|
||||||
if len(conffiles) < 1:
|
if len(conffiles) < 1:
|
||||||
raise
|
raise
|
||||||
fileValid = False
|
fileValid = False
|
||||||
while not fileValid:
|
while not fileValid:
|
||||||
print ('Seleziona un file di configurazione per la lingua:')
|
print ('Seleziona un file di configurazione per la lingua:')
|
||||||
for cf in enumerate(conffiles):
|
for cf in enumerate(conffiles):
|
||||||
print('[{0}] - {1}'.format(cf[0],cf[1]))
|
print('[{0}] - {1}'.format(cf[0],cf[1]))
|
||||||
try:
|
try:
|
||||||
fn = int(input('Scrivi il numero del file e premi Invio: '))
|
fn = int(input('Scrivi il numero del file e premi Invio: '))
|
||||||
if (fn > len(conffiles)-1 or fn < 0):
|
if (fn > len(conffiles)-1 or fn < 0):
|
||||||
raise
|
raise
|
||||||
fileValid = True
|
fileValid = True
|
||||||
except:
|
except:
|
||||||
print('Scusa, non ho capito bene, ricominciamo..\n')
|
print('Scusa, non ho capito bene, ricominciamo..\n')
|
||||||
fileValid = False
|
fileValid = False
|
||||||
except:
|
except:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS!! File di configurazione non selezionato o non presente..', Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS!! File di configurazione non selezionato o non presente..', Style.RESET_ALL)
|
||||||
input()
|
input()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print('\nApro il file di configurazione [{}]...'.format(conffiles[fn]))
|
print('\nApro il file di configurazione [{}]...'.format(conffiles[fn]))
|
||||||
fp = open(conffiles[fn],'r')
|
fp = open(conffiles[fn],'r')
|
||||||
cfg = json.load(fp)
|
cfg = json.load(fp)
|
||||||
fp.close
|
fp.close
|
||||||
try:
|
try:
|
||||||
print('Carico i parametri...')
|
print('Carico i parametri...')
|
||||||
docParams=cfg['docStruct']
|
docParams=cfg['docStruct']
|
||||||
basePath=cfg['INworkPath']+"{0}.{1}"
|
basePath=cfg['INworkPath']+"{0}.{1}"
|
||||||
settings=cfg['settings']
|
settings=cfg['settings']
|
||||||
delChars=settings['delChars'].split('|')
|
delChars=settings['delChars'].split('|')
|
||||||
docSep=re.compile(docParams['docSep'])
|
docSep=re.compile(docParams['docSep'])
|
||||||
except:
|
except:
|
||||||
print(Fore.LIGHTRED_EX,'OOPS! Qualcosa e\' andato storto, non riesco a caricare la configurazione, controlla la sintassi! :)', Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX,'OOPS! Qualcosa e\' andato storto, non riesco a caricare la configurazione, controlla la sintassi! :)', Style.RESET_ALL)
|
||||||
input()
|
input()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non trovo il file di configurazione: {}'.format(e), Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non trovo il file di configurazione: {}'.format(e), Style.RESET_ALL)
|
||||||
input()
|
input()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
files=[]
|
files=[]
|
||||||
try:
|
try:
|
||||||
print('Ottengo la lista dei file da separare...')
|
print('Ottengo la lista dei file da separare...')
|
||||||
if settings['loadTXT']:
|
if settings['loadTXT']:
|
||||||
files+=glob(basePath.format('*','txt'))
|
files+=glob(basePath.format('*','txt'))
|
||||||
if settings['loadDOCX']:
|
if settings['loadDOCX']:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS! Scusa ma non posso accontentarti, per ora non so leggere i file DOCX.. :(', Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS! Scusa ma non posso accontentarti, per ora non so leggere i file DOCX.. :(', Style.RESET_ALL)
|
||||||
input()
|
input()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
#files+=glob(basePath.format('*','docx'))
|
#files+=glob(basePath.format('*','docx'))
|
||||||
if len(files)<=0:
|
if len(files)<=0:
|
||||||
raise
|
raise
|
||||||
pprint(files)
|
pprint(files)
|
||||||
while True:
|
while True:
|
||||||
r=input('\nVuoi davvero bananaSPLITTARE questi documenti? [y/n]:')
|
r=input('\nVuoi davvero bananaSPLITTARE questi documenti? [y/n]:')
|
||||||
r.strip()
|
r.strip()
|
||||||
if r=='Y' or r =='y':
|
if r=='Y' or r =='y':
|
||||||
break
|
break
|
||||||
elif r=='n' or r=='N':
|
elif r=='n' or r=='N':
|
||||||
print('OK! Nessun problema, ci vediamo dopo :)')
|
print('OK! Nessun problema, ci vediamo dopo :)')
|
||||||
input()
|
input()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
print('Non ho capito la risposta, sii un po\' piu\' specifico... [y/n]\n')
|
print('Non ho capito la risposta, sii un po\' piu\' specifico... [y/n]\n')
|
||||||
pass
|
pass
|
||||||
if settings['removeOldFiles']:
|
|
||||||
print("Rimuovo i vecchi file dalla cartella di destinazione..")
|
|
||||||
for x in glob(cfg['OUTworkPath']+'*.txt'):
|
|
||||||
os.remove(x)
|
|
||||||
except:
|
except:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a trovare nessun file da leggere :(', Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a trovare nessun file da leggere :(', Style.RESET_ALL)
|
||||||
input()
|
input()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
try:
|
||||||
|
if settings['removeOldFiles']:
|
||||||
|
print("Rimuovo i vecchi file dalla cartella di destinazione..")
|
||||||
|
for x in glob(cfg['OUTworkPath']+'*.txt'):
|
||||||
|
os.remove(x)
|
||||||
|
except:
|
||||||
|
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a rimuovere i vecchi file :(', Style.RESET_ALL)
|
||||||
|
|
||||||
lastTime=time.time()
|
lastTime=time.time()
|
||||||
fileCounter = 1
|
fileCounter = 1
|
||||||
fileBodyCounter = 1
|
fileBodyCounter = 1
|
||||||
@@ -128,201 +130,201 @@ totSkipped=0
|
|||||||
|
|
||||||
# per ogni file nella lista
|
# per ogni file nella lista
|
||||||
for f in files:
|
for f in files:
|
||||||
s=status['first']
|
s=status['first']
|
||||||
prevLine=''
|
prevLine=''
|
||||||
doc={'title':'',
|
doc={'title':'',
|
||||||
'date':'',
|
'date':'',
|
||||||
'content':[]
|
'content':[]
|
||||||
}
|
}
|
||||||
fileContent=''
|
fileContent=''
|
||||||
tempContent=list()
|
tempContent=list()
|
||||||
fileBaseName=os.path.split(f)[1].split('.')[0]
|
fileBaseName=os.path.split(f)[1].split('.')[0]
|
||||||
fileBodyList=list()
|
fileBodyList=list()
|
||||||
fileContent = list()
|
fileContent = list()
|
||||||
try:
|
try:
|
||||||
print()
|
print()
|
||||||
print('-'*50)
|
print('-'*50)
|
||||||
print('Apro il file: {}'.format(fileBaseName))
|
print('Apro il file: {}'.format(fileBaseName))
|
||||||
fp = open(f,mode='r', encoding=settings['encoding'])
|
fp = open(f,mode='r', encoding=settings['encoding'])
|
||||||
fileContent=fp.readlines() #leggi le linee del file
|
fileContent=fp.readlines() #leggi le linee del file
|
||||||
fp.close()
|
fp.close()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco ad aprire il file: {}'.format(fileBaseName), Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco ad aprire il file: {}'.format(fileBaseName), Style.RESET_ALL)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print('Elimino le righe vuote...')
|
print('Elimino le righe vuote...')
|
||||||
for ll in fileContent:
|
for ll in fileContent:
|
||||||
for c in delChars:
|
for c in delChars:
|
||||||
ll=ll.replace(c,'')
|
ll=ll.replace(c,'')
|
||||||
if ll not in ['\n','\r']:
|
if ll not in ['\n','\r']:
|
||||||
tempContent.append(ll)
|
tempContent.append(ll)
|
||||||
fileContent=deepcopy(tempContent)
|
fileContent=deepcopy(tempContent)
|
||||||
tempContent=list()
|
tempContent=list()
|
||||||
|
|
||||||
print('Individuo il contenuto...')
|
print('Individuo il contenuto...')
|
||||||
docNumber = 0
|
docNumber = 0
|
||||||
docSkipped = 0
|
docSkipped = 0
|
||||||
bodyCounter = 0
|
bodyCounter = 0
|
||||||
duplicateNumber = 0
|
duplicateNumber = 0
|
||||||
docDate = {}
|
docDate = {}
|
||||||
prevLine = ''
|
prevLine = ''
|
||||||
newsPaperName = ''
|
newsPaperName = ''
|
||||||
titleBegin = False
|
titleBegin = False
|
||||||
|
|
||||||
for l in fileContent: #per ogni linea del file
|
for l in fileContent: #per ogni linea del file
|
||||||
lineWords=l.lstrip().split(' ') #dividi la riga in parole
|
lineWords=l.lstrip().split(' ') #dividi la riga in parole
|
||||||
if s==status['first']:
|
if s==status['first']:
|
||||||
try:
|
try:
|
||||||
#prendo il numero di documento per vedere se ci sono buchi
|
#prendo il numero di documento per vedere se ci sono buchi
|
||||||
try:
|
try:
|
||||||
nn = parse.parse("{current:d} Of {total} Documents",l.strip().capitalize()).named
|
nn = parse.parse("{current:d} Of {total} Documents",l.strip().capitalize()).named
|
||||||
if nn["current"]-docNumber==1:
|
if nn["current"]-docNumber==1:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if settings["showSkipped"]:
|
if settings["showSkipped"]:
|
||||||
print(Fore.LIGHTRED_EX,"OOPS!! Il conto dei documenti non torna! LexisNexis \
|
print(Fore.LIGHTRED_EX,"OOPS!! Il conto dei documenti non torna! LexisNexis \
|
||||||
ne ha saltato qualcuno!\nPrecedente:{0}-Attuale:{1}".format(docNumber,nn["current"]), Style.RESET_ALL)
|
ne ha saltato qualcuno!\nPrecedente:{0}-Attuale:{1}".format(docNumber,nn["current"]), Style.RESET_ALL)
|
||||||
docSkipped+=1
|
docSkipped+=1
|
||||||
docNumber = nn["current"]
|
docNumber = nn["current"]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if (lineWords[settings['monthPosition']]).capitalize() in docParams['dateWords']:
|
if (lineWords[settings['monthPosition']]).capitalize() in docParams['dateWords']:
|
||||||
try:
|
try:
|
||||||
docDate=parse.parse(docParams['dateFormat'],l).named
|
docDate=parse.parse(docParams['dateFormat'],l).named
|
||||||
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
docDate['month']=docDate['month'].lstrip().rstrip().capitalize()
|
||||||
docDate['month']=docParams['dateWords'].index(docDate['month'])+1
|
docDate['month']=docParams['dateWords'].index(docDate['month'])+1
|
||||||
title = ''
|
title = ''
|
||||||
titleBegin=True
|
titleBegin=True
|
||||||
if settings['getNewsPaperName']:
|
if settings['getNewsPaperName']:
|
||||||
try:
|
try:
|
||||||
if prevLine.split(' ')[0].strip().isalpha():
|
if prevLine.split(' ')[0].strip().isalpha():
|
||||||
newsPaperName = prevLine.strip()
|
newsPaperName = prevLine.strip()
|
||||||
else:
|
else:
|
||||||
newsPaperName = settings['nameNotFoundStr']
|
newsPaperName = settings['nameNotFoundStr']
|
||||||
except:
|
except:
|
||||||
print(Fore.LIGHTRED_EX, "OOPS! E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
print(Fore.LIGHTRED_EX, "OOPS! E' successo qualcosa mentre stavo cercando il nome della pubblicazione,\
|
||||||
controlla i file di uscita! \n\t[{}]".format(prevLine.strip()), Style.RESET_ALL)
|
controlla i file di uscita! \n\t[{}]".format(prevLine.strip()), Style.RESET_ALL)
|
||||||
else:
|
else:
|
||||||
newsPaperName = settings['nameNotFoundStr']
|
newsPaperName = settings['nameNotFoundStr']
|
||||||
except:
|
except:
|
||||||
print(Fore.LIGHTRED_EX, "OOPS! Ho trovato una riga ambigua.. potrebbe essere una data ma non so: \n\t[{}]". format(l.strip('\r\n')),
|
print(Fore.LIGHTRED_EX, "OOPS! Ho trovato una riga ambigua.. potrebbe essere una data ma non so: \n\t[{}]". format(l.strip('\r\n')),
|
||||||
Style.RESET_ALL)
|
Style.RESET_ALL)
|
||||||
elif lineWords[0] in docParams['headWords']:
|
elif lineWords[0] in docParams['headWords']:
|
||||||
s=status['head']
|
s=status['head']
|
||||||
newDoc=deepcopy(doc)
|
newDoc=deepcopy(doc)
|
||||||
newDoc['title']=title
|
newDoc['title']=title
|
||||||
newDoc['date']=docDate
|
newDoc['date']=docDate
|
||||||
newDoc['newsPaperName'] = newsPaperName
|
newDoc['newsPaperName'] = newsPaperName
|
||||||
titleBegin=False
|
titleBegin=False
|
||||||
else:
|
else:
|
||||||
if titleBegin:
|
if titleBegin:
|
||||||
title += l.strip().capitalize()
|
title += l.strip().capitalize()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print (Fore.LIGHTRED_EX, 'OOPS! Errore inaspettato, contatta il tuo sviluppatore di fiducia!', Style.RESET_ALL)
|
print (Fore.LIGHTRED_EX, 'OOPS! Errore inaspettato, contatta il tuo sviluppatore di fiducia!', Style.RESET_ALL)
|
||||||
elif s==status['head']:
|
elif s==status['head']:
|
||||||
if lineWords[0] not in docParams['headWords']: #se la prima parola non e' tra quelle di inizio
|
if lineWords[0] not in docParams['headWords']: #se la prima parola non e' tra quelle di inizio
|
||||||
tempContent.append(l) # vuol dire che ho trovato l'articolo
|
tempContent.append(l) # vuol dire che ho trovato l'articolo
|
||||||
s=status['body']
|
s=status['body']
|
||||||
elif s==status['body']:
|
elif s==status['body']:
|
||||||
if not lineWords[0] in docParams['tailWords']: #se la prima parola non e' tra quelle di fine
|
if not lineWords[0] in docParams['tailWords']: #se la prima parola non e' tra quelle di fine
|
||||||
if settings['delLF']:
|
if settings['delLF']:
|
||||||
tempContent.append(l.strip('\n')) #allora sto leggendo l'articolo
|
tempContent.append(l.strip('\n')) #allora sto leggendo l'articolo
|
||||||
else:
|
else:
|
||||||
tempContent.append(l)
|
tempContent.append(l)
|
||||||
else:
|
else:
|
||||||
s=status['tail']
|
s=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
|
||||||
print(Fore.YELLOW, "HEY! Ho individuato una separatore valido prima che si chiusesse l'articolo precedente, controlla i tuoi file in uscita!\n\
|
print(Fore.YELLOW, "HEY! 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'errore dovrebbe essere intorno all'articolo {} ma non sono sicuro! \n\t\t[{}]".format(docNumber,
|
||||||
l.strip()), Style.RESET_ALL)
|
l.strip()), Style.RESET_ALL)
|
||||||
s=status['tail']
|
s=status['tail']
|
||||||
anomaly = True
|
anomaly = True
|
||||||
elif s==status['tail']: #cerco il separatore di articoli e aggiungo quello letto alla lista
|
elif s==status['tail']: #cerco il separatore di articoli e aggiungo quello letto alla lista
|
||||||
if docSep.match(l) is not None or anomaly:
|
if docSep.match(l) is not None or anomaly:
|
||||||
s=status['first']
|
s=status['first']
|
||||||
anomaly = False
|
anomaly = False
|
||||||
if settings['delWordBreak']:
|
if settings['delWordBreak']:
|
||||||
tempContent=[ll.replace('-\n', '') for ll in tempContent]
|
tempContent=[ll.replace('-\n', '') for ll in tempContent]
|
||||||
newDoc['content']=deepcopy(''.join(tempContent))
|
newDoc['content']=deepcopy(''.join(tempContent))
|
||||||
fileBodyList.append(deepcopy(newDoc))
|
fileBodyList.append(deepcopy(newDoc))
|
||||||
tempContent=list()
|
tempContent=list()
|
||||||
bodyCounter +=1
|
bodyCounter +=1
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
prevLine=l
|
prevLine=l
|
||||||
pass
|
pass
|
||||||
print ('Nel file ho trovato {0} articoli..'.format(bodyCounter))
|
print ('Nel file ho trovato {0} articoli..'.format(bodyCounter))
|
||||||
if docSkipped > 0:
|
if docSkipped > 0:
|
||||||
print (Fore.YELLOW, 'Attentione, LexisNexis ne ha saltati {} !!!'.format(docSkipped), Style.RESET_ALL)
|
print (Fore.YELLOW, 'Attentione, LexisNexis ne ha saltati {} !!!'.format(docSkipped), Style.RESET_ALL)
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if bodyCounter >= 1:
|
if bodyCounter >= 1:
|
||||||
if settings['removeDuplicates']:
|
if settings['removeDuplicates']:
|
||||||
print ('Controllo se ci sono dei duplicati..')
|
print ('Controllo se ci sono dei duplicati..')
|
||||||
titleList=[]
|
titleList=[]
|
||||||
duplicateList=[]
|
duplicateList=[]
|
||||||
duplicateNumber=0
|
duplicateNumber=0
|
||||||
for idx, ff in enumerate(fileBodyList):
|
for idx, ff in enumerate(fileBodyList):
|
||||||
if ff['title'] not in titleList:
|
if ff['title'] not in titleList:
|
||||||
titleList.append(ff['title'])
|
titleList.append(ff['title'])
|
||||||
ff['duplicate']=False
|
ff['duplicate']=False
|
||||||
fileBodyList[idx]=ff
|
fileBodyList[idx]=ff
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if ff['title'] not in duplicateList:
|
if ff['title'] not in duplicateList:
|
||||||
duplicateList.append(ff['title'])
|
duplicateList.append(ff['title'])
|
||||||
if settings['showRemovedDuplicates']:
|
if settings['showRemovedDuplicates']:
|
||||||
print ('Duplicato: {}'.format(ff['title'].strip()))
|
print ('Duplicato: {}'.format(ff['title'].strip()))
|
||||||
ff['duplicate'] = True
|
ff['duplicate'] = True
|
||||||
fileBodyList[idx]=ff
|
fileBodyList[idx]=ff
|
||||||
duplicateNumber+=1
|
duplicateNumber+=1
|
||||||
print ('Ho rimosso {} duplicati di {} articoli..\n'. format(duplicateNumber, len(duplicateList)))
|
print ('Ho rimosso {} duplicati di {} articoli..\n'. format(duplicateNumber, len(duplicateList)))
|
||||||
else:
|
else:
|
||||||
for idx, ff in enumerate(fileBodyList):
|
for idx, ff in enumerate(fileBodyList):
|
||||||
ff['duplicate']=False
|
ff['duplicate']=False
|
||||||
fileBodyList[idx]=ff
|
fileBodyList[idx]=ff
|
||||||
print('Salto il controllo dei duplicati..')
|
print('Salto il controllo dei duplicati..')
|
||||||
pass
|
pass
|
||||||
if settings['saveSeparateFiles']:
|
if settings['saveSeparateFiles']:
|
||||||
print ('Salvo gli articoli in file separati...')
|
print ('Salvo gli articoli in file separati...')
|
||||||
print ('Persorso: {0}'.format(cfg['OUTworkPath'].format('nomeFile')))
|
print ('Persorso: {0}'.format(cfg['OUTworkPath'].format('nomeFile')))
|
||||||
for ff in fileBodyList:
|
for ff in fileBodyList:
|
||||||
try:
|
try:
|
||||||
if ff['duplicate'] == False:
|
if ff['duplicate'] == False:
|
||||||
fileName=cfg['OUTnameFormat'].format(title=slugify(ff['title'][:settings['maxTitleLen']]),\
|
fileName=cfg['OUTnameFormat'].format(title=slugify(ff['title'][:settings['maxTitleLen']]),\
|
||||||
filename=slugify(fileBaseName),\
|
filename=slugify(fileBaseName),\
|
||||||
docnum=fileBodyCounter,\
|
docnum=fileBodyCounter,\
|
||||||
papername=ff['newsPaperName'].strip(),\
|
papername=ff['newsPaperName'].strip(),\
|
||||||
**ff['date'])
|
**ff['date'])
|
||||||
out=open(cfg['OUTworkPath']+'{0}'.format(fileName),'wb')
|
out=open(cfg['OUTworkPath']+'{0}'.format(fileName),'wb')
|
||||||
if settings['includeTitle']:
|
if settings['includeTitle']:
|
||||||
ff['content'] = ff['title']+os.linesep+ff['content']
|
ff['content'] = ff['title']+os.linesep+ff['content']
|
||||||
out.write(ff['content'].encode(settings['encoding']))
|
out.write(ff['content'].encode(settings['encoding']))
|
||||||
out.close()
|
out.close()
|
||||||
fileBodyCounter+=1
|
fileBodyCounter+=1
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a scrivere il file: {}'.format(e), Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a scrivere il file: {}'.format(e), Style.RESET_ALL)
|
||||||
continue
|
continue
|
||||||
if settings['saveBodyFile']:
|
if settings['saveBodyFile']:
|
||||||
print('Salvo gli articoli in un singolo file vicino agli originali...')
|
print('Salvo gli articoli in un singolo file vicino agli originali...')
|
||||||
print ('Persorso: {0}'.format(cfg['OUTworkPath'].format('nomeFile')))
|
print ('Persorso: {0}'.format(cfg['OUTworkPath'].format('nomeFile')))
|
||||||
try:
|
try:
|
||||||
fileName=slugify(fileBaseName)
|
fileName=slugify(fileBaseName)
|
||||||
fileName='BODYFILE_{0}_{1}.txt'.format(fileCounter,fileName[:settings['maxTitleLen']])
|
fileName='BODYFILE_{0}_{1}.txt'.format(fileCounter,fileName[:settings['maxTitleLen']])
|
||||||
fileContent = os.linesep.join([cc['content'] for cc in fileBodyList])
|
fileContent = os.linesep.join([cc['content'] for cc in fileBodyList])
|
||||||
out=open(cfg['OUTworkPath']+'{0}'.format(fileName),'wb')
|
out=open(cfg['OUTworkPath']+'{0}'.format(fileName),'wb')
|
||||||
out.write(fileContent.encode(settings['encoding']))
|
out.write(fileContent.encode(settings['encoding']))
|
||||||
out.close()
|
out.close()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a scrivere il file: {}'.format(e), Style.RESET_ALL)
|
print(Fore.LIGHTRED_EX, 'OOPS! Qualcosa e\' andato storto, non riesco a scrivere il file: {}'.format(e), Style.RESET_ALL)
|
||||||
continue
|
continue
|
||||||
fileCounter+=1
|
fileCounter+=1
|
||||||
totSkipped+=docSkipped
|
totSkipped+=docSkipped
|
||||||
totFound+=bodyCounter-duplicateNumber
|
totFound+=bodyCounter-duplicateNumber
|
||||||
else:
|
else:
|
||||||
print('[{0}] non contiene articoli, \n controlla meglio le parole chiave! SGRUNT'.format(fileBaseName))
|
print('[{0}] non contiene articoli, \n controlla meglio le parole chiave! SGRUNT'.format(fileBaseName))
|
||||||
print('-'*50)
|
print('-'*50)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print (Fore.LIGHTYELLOW_EX, 'bananaSPLIT ha concluso con successo in {0:1.3f} secondi, \n\
|
print (Fore.LIGHTYELLOW_EX, 'bananaSPLIT ha concluso con successo in {0:1.3f} secondi, \n\
|
||||||
|
|||||||
@@ -37,8 +37,7 @@
|
|||||||
"DOCUMENT-TYPE:",
|
"DOCUMENT-TYPE:",
|
||||||
"CHARTS:"
|
"CHARTS:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"settings":
|
|
||||||
"settings": {
|
"settings": {
|
||||||
"encoding": "utf-8",
|
"encoding": "utf-8",
|
||||||
"monthPosition": 0,
|
"monthPosition": 0,
|
||||||
Reference in New Issue
Block a user