# Import Module
import pdfx
import os
import shutil

src='./documente'
dst1='./descarcate_temp'
dst2='./descarcate'

_intrare=[f for f in os.listdir(src) if '.pdf' in f]
intrare = []
for item in _intrare:
    intrare += [item]
    intrare += [item+'.infos.json']
print(intrare)

for file in _intrare:
    pdf = pdfx.PDFx(src + '/' + file)
    pdf.download_pdfs(dst1)

os.mkdir(dst2)
for currentpath, folders, files in os.walk(dst1):
    for file in files:
        if not file in intrare:        
            curent_pdf = os.path.join(currentpath, file)
            target_pdf = dst2 + '/' + file
            shutil.move(curent_pdf, target_pdf)

shutil.rmtree(dst1)

for item in os.listdir(dst2):
    shutil.move(dst2 + '/' + item, src + '/' + item)    

shutil.rmtree(dst2)

