From 067240b8a7bfd34458e3188b40ad839c9f50a35b Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 28 Oct 2022 22:18:22 +0200 Subject: [PATCH] Revert "Close db" This reverts commit 29590525bacfebd1ce80b6b2d6c679805559cd79. --- partitioncloud/modules/search.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/partitioncloud/modules/search.py b/partitioncloud/modules/search.py index 9b2fd9d..692a8a5 100644 --- a/partitioncloud/modules/search.py +++ b/partitioncloud/modules/search.py @@ -44,6 +44,7 @@ def online_search(query, num_queries): """ Renvoie les 3 résultats les plus pertinents depuis google """ + db = get_db() query = f"partition filetype:pdf {query}" partitions = [] results = googlesearch.search( @@ -56,7 +57,6 @@ def online_search(query, num_queries): while True: try: uuid = str(uuid4()) - db = get_db() db.execute( """ INSERT INTO search_results (uuid) @@ -65,8 +65,8 @@ def online_search(query, num_queries): (uuid,) ) db.commit() - db.close() urllib.request.urlretrieve(element, f"partitioncloud/search-partitions/{uuid}.pdf") + os.system( f'/usr/bin/convert -thumbnail\ "178^>" -background white -alpha \ @@ -85,8 +85,6 @@ def online_search(query, num_queries): pass except (urllib.error.HTTPError, urllib.error.URLError) as e: print(e, element) - - db = get_db() db.execute( """ DELETE FROM search_results @@ -95,7 +93,6 @@ def online_search(query, num_queries): (uuid,) ) db.commit() - db.close() break return partitions @@ -127,5 +124,4 @@ def flush_cache(): DELETE FROM search_results WHERE creation_time <= datetime('now', '-15 minutes', 'localtime') """ - ) - db.close() \ No newline at end of file + ) \ No newline at end of file