From 5b904e7abb76648de309af8e97ec456641f8b7bb Mon Sep 17 00:00:00 2001 From: MancunianSam Date: Fri, 13 Dec 2024 09:55:57 +0000 Subject: [PATCH] Fix error if puid doesn't exist --- .gitignore | 3 ++- results.py | 10 +++++++++- templates/home.html | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 52bf79a..6c7e44c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ package .idea .venv -site/ \ No newline at end of file +site/ +indexes diff --git a/results.py b/results.py index 126ddd3..31e7d4e 100644 --- a/results.py +++ b/results.py @@ -8,6 +8,14 @@ ) +def puid_exists(puid): + conn = sqlite3.connect("indexes") + cursor = conn.cursor() + cursor.execute("SELECT path from indexes where path = ?", (puid,)) + rows = cursor.fetchall() + return len(rows) > 0 + + def search(search_string): conn = sqlite3.connect('indexes') cur = conn.cursor() @@ -20,7 +28,7 @@ def search(search_string): def lambda_handler(event, _): query_params = event.get("queryStringParameters", {}) search_term = query_params.get("q") if query_params else None - if re.search(r'^(x-)?fmt\/\d{1,5}$', search_term) is not None: + if re.search(r'^(x-)?fmt\/\d{1,5}$', search_term) is not None and puid_exists(search_term): return { "statusCode": 302, "headers": {'Location': f'{search_term}.html'} diff --git a/templates/home.html b/templates/home.html index eabc890..485de3f 100644 --- a/templates/home.html +++ b/templates/home.html @@ -6,4 +6,6 @@

Search PRONOM
Contribute to PRONOM +
+ View signature files

\ No newline at end of file