mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Runs the pre-commit hooks over all the Python files
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
import dateutil.parser
|
||||
|
||||
import requests
|
||||
from django.conf import settings
|
||||
|
||||
from documents.parsers import DocumentParser, ParseError, make_thumbnail_from_pdf
|
||||
from documents.parsers import DocumentParser
|
||||
from documents.parsers import make_thumbnail_from_pdf
|
||||
from documents.parsers import ParseError
|
||||
from tika import parser
|
||||
|
||||
|
||||
@@ -20,7 +21,9 @@ class TikaDocumentParser(DocumentParser):
|
||||
self.archive_path = self.convert_to_pdf(document_path, file_name)
|
||||
|
||||
return make_thumbnail_from_pdf(
|
||||
self.archive_path, self.tempdir, self.logging_group
|
||||
self.archive_path,
|
||||
self.tempdir,
|
||||
self.logging_group,
|
||||
)
|
||||
|
||||
def extract_metadata(self, document_path, mime_type):
|
||||
@@ -53,7 +56,7 @@ class TikaDocumentParser(DocumentParser):
|
||||
except Exception as err:
|
||||
raise ParseError(
|
||||
f"Could not parse {document_path} with tika server at "
|
||||
f"{tika_server}: {err}"
|
||||
f"{tika_server}: {err}",
|
||||
)
|
||||
|
||||
self.text = parsed["content"].strip()
|
||||
@@ -74,22 +77,23 @@ class TikaDocumentParser(DocumentParser):
|
||||
url = gotenberg_server + "/forms/libreoffice/convert"
|
||||
|
||||
self.log("info", f"Converting {document_path} to PDF as {pdf_path}")
|
||||
files = {
|
||||
"files": (
|
||||
file_name or os.path.basename(document_path),
|
||||
open(document_path, "rb"),
|
||||
)
|
||||
}
|
||||
headers = {}
|
||||
with open(document_path, "rb") as document_handle:
|
||||
files = {
|
||||
"files": (
|
||||
file_name or os.path.basename(document_path),
|
||||
document_handle,
|
||||
),
|
||||
}
|
||||
headers = {}
|
||||
|
||||
try:
|
||||
response = requests.post(url, files=files, headers=headers)
|
||||
response.raise_for_status() # ensure we notice bad responses
|
||||
except Exception as err:
|
||||
raise ParseError(f"Error while converting document to PDF: {err}")
|
||||
try:
|
||||
response = requests.post(url, files=files, headers=headers)
|
||||
response.raise_for_status() # ensure we notice bad responses
|
||||
except Exception as err:
|
||||
raise ParseError(f"Error while converting document to PDF: {err}")
|
||||
|
||||
file = open(pdf_path, "wb")
|
||||
file.write(response.content)
|
||||
file.close()
|
||||
with open(pdf_path, "wb") as file:
|
||||
file.write(response.content)
|
||||
file.close()
|
||||
|
||||
return pdf_path
|
||||
|
Reference in New Issue
Block a user