check search pdfs

This commit is contained in:
augustin64 2024-02-21 15:53:49 +01:00
parent 9a6d08d2e1
commit 3f83f1c44a
4 changed files with 21 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import threading
import socket
import os
import pypdf
import googlesearch
from .db import get_db
@ -52,12 +53,17 @@ def local_search(query, partitions):
def download_search_result(element, instance_path):
uuid = element["uuid"]
url = element["url"]
filename = f"{instance_path}/search-partitions/{uuid}.pdf"
try:
urllib.request.urlretrieve(url, f"{instance_path}/search-partitions/{uuid}.pdf")
urllib.request.urlretrieve(url, filename)
pypdf.PdfReader(filename)
except (urllib.error.HTTPError, urllib.error.URLError):
with open(f"{instance_path}/search-partitions/{uuid}.pdf", 'a', encoding="utf8") as _:
except (urllib.error.HTTPError, urllib.error.URLError,
pypdf.errors.PdfReadError, pypdf.errors.PdfStreamError):
if os.path.exists(filename):
os.remove(filename)
with open(filename, 'a', encoding="utf8") as _:
pass # Create empty file

View File

@ -2,4 +2,5 @@ flask
flask-babel
google
colorama
pypdf
qrcode

View File

@ -180,3 +180,11 @@ def move_thumbnails():
def install_babel():
utils.install_package("flask-babel")
"""
v1.8.*
"""
def install_pypdf():
utils.install_package("pypdf")

View File

@ -35,7 +35,8 @@ hooks = [
("v1.4.1", [("Install qrcode", v1_hooks.install_qrcode)]),
("v1.5.0", [("Move to instance directory", v1_hooks.move_instance)]),
("v1.5.1", [("Move thumbnails", v1_hooks.move_thumbnails)]),
("v1.7.0", [("Install babel", v1_hooks.install_babel)])
("v1.7.0", [("Install babel", v1_hooks.install_babel)]),
("v1.8.2", [("Install pypdf", v1_hooks.install_pypdf)])
]