Last active
April 12, 2023 13:49
-
-
Save sergiolucero/e3253ac0d5f16e309963194cc4ecb967 to your computer and use it in GitHub Desktop.
pdf legal conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob, fitz, pandas as pd | |
files = glob.glob('folder/*.pdf') | |
texts = [' '.join([page.get_text() for page in fitz.open(fn)]) | |
for fn in files] | |
df = pd.DataFrame(dict(file=files, text=texts)) | |
df['cuerpo'] = df.text.apply(lambda t: remove_headandsentence) | |
df['fallo'] = df.text.apply(lambda t: extract_fallo) | |
df.to_csv('sentencias.csv', index=False) | |
print(sum(len(txt) for txt in texts)) |
pip install PyMuPDF
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import boto3
import fitz
from datetime import datetime
translate = boto3.client('translate')
source_language_code = 'en'; target_language_code = 'es'
SIZE_LIMIT = 9500
get_text = lambda fn: ' '.join([page.get_text() for page in fitz.open(fn)])
def xl8(filename):
document_text = get_text(filename)
nChars = len(document_text)
nChunks = nChars/SIZE_LIMIT
translated_text = ''
def pdf2spa(filename):
txt = xl8(filename)
open(filename.replace('.pdf','.txt'), 'w').write(txt)