mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-01-23 17:26:26 +01:00
Close db
This commit is contained in:
parent
612a799656
commit
29590525ba
@ -44,7 +44,6 @@ def online_search(query, num_queries):
|
|||||||
"""
|
"""
|
||||||
Renvoie les 3 résultats les plus pertinents depuis google
|
Renvoie les 3 résultats les plus pertinents depuis google
|
||||||
"""
|
"""
|
||||||
db = get_db()
|
|
||||||
query = f"partition filetype:pdf {query}"
|
query = f"partition filetype:pdf {query}"
|
||||||
partitions = []
|
partitions = []
|
||||||
results = googlesearch.search(
|
results = googlesearch.search(
|
||||||
@ -57,6 +56,7 @@ def online_search(query, num_queries):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
uuid = str(uuid4())
|
uuid = str(uuid4())
|
||||||
|
db = get_db()
|
||||||
db.execute(
|
db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO search_results (uuid)
|
INSERT INTO search_results (uuid)
|
||||||
@ -65,8 +65,8 @@ def online_search(query, num_queries):
|
|||||||
(uuid,)
|
(uuid,)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
db.close()
|
||||||
urllib.request.urlretrieve(element, f"partitioncloud/search-partitions/{uuid}.pdf")
|
urllib.request.urlretrieve(element, f"partitioncloud/search-partitions/{uuid}.pdf")
|
||||||
|
|
||||||
os.system(
|
os.system(
|
||||||
f'/usr/bin/convert -thumbnail\
|
f'/usr/bin/convert -thumbnail\
|
||||||
"178^>" -background white -alpha \
|
"178^>" -background white -alpha \
|
||||||
@ -85,6 +85,8 @@ def online_search(query, num_queries):
|
|||||||
pass
|
pass
|
||||||
except (urllib.error.HTTPError, urllib.error.URLError) as e:
|
except (urllib.error.HTTPError, urllib.error.URLError) as e:
|
||||||
print(e, element)
|
print(e, element)
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
db.execute(
|
db.execute(
|
||||||
"""
|
"""
|
||||||
DELETE FROM search_results
|
DELETE FROM search_results
|
||||||
@ -93,6 +95,7 @@ def online_search(query, num_queries):
|
|||||||
(uuid,)
|
(uuid,)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
db.close()
|
||||||
break
|
break
|
||||||
return partitions
|
return partitions
|
||||||
|
|
||||||
@ -124,4 +127,5 @@ def flush_cache():
|
|||||||
DELETE FROM search_results
|
DELETE FROM search_results
|
||||||
WHERE creation_time <= datetime('now', '-15 minutes', 'localtime')
|
WHERE creation_time <= datetime('now', '-15 minutes', 'localtime')
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
db.close()
|
Loading…
Reference in New Issue
Block a user