mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-04-22 13:43:55 +02:00
Fix online search sometimes blocking local search
This commit is contained in:
parent
1d02292c61
commit
971d54af41
@ -5,12 +5,15 @@ Module implémentant la recherche de partitions par mots-clés
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import threading
|
import threading
|
||||||
|
import socket
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import googlesearch
|
import googlesearch
|
||||||
|
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
|
|
||||||
|
socket.setdefaulttimeout(5) # Maximum time before we give up on downloading a file (dead url)
|
||||||
|
|
||||||
|
|
||||||
def local_search(query, partitions):
|
def local_search(query, partitions):
|
||||||
"""
|
"""
|
||||||
@ -60,35 +63,40 @@ def online_search(query, num_queries):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
query = f"partition filetype:pdf {query}"
|
query = f"partition filetype:pdf {query}"
|
||||||
partitions = []
|
partitions = []
|
||||||
results = googlesearch.search(
|
|
||||||
query,
|
|
||||||
num=num_queries,
|
|
||||||
stop=num_queries,
|
|
||||||
pause=0.2
|
|
||||||
)
|
|
||||||
for element in results:
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
uuid = str(uuid4())
|
|
||||||
db.execute(
|
|
||||||
"""
|
|
||||||
INSERT INTO search_results (uuid, url)
|
|
||||||
VALUES (?, ?)
|
|
||||||
""",
|
|
||||||
(uuid, element,)
|
|
||||||
)
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
partitions.append(
|
try:
|
||||||
{
|
results = googlesearch.search(
|
||||||
"name": element.split("://")[1].split("/")[0],
|
query,
|
||||||
"uuid": uuid,
|
num=num_queries,
|
||||||
"url": element
|
stop=num_queries,
|
||||||
}
|
pause=0.2
|
||||||
)
|
)
|
||||||
break
|
for element in results:
|
||||||
except db.IntegrityError:
|
while True:
|
||||||
pass
|
try:
|
||||||
|
uuid = str(uuid4())
|
||||||
|
db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO search_results (uuid, url)
|
||||||
|
VALUES (?, ?)
|
||||||
|
""",
|
||||||
|
(uuid, element,)
|
||||||
|
)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
partitions.append(
|
||||||
|
{
|
||||||
|
"name": element.split("://")[1].split("/")[0],
|
||||||
|
"uuid": uuid,
|
||||||
|
"url": element
|
||||||
|
}
|
||||||
|
)
|
||||||
|
break
|
||||||
|
except db.IntegrityError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
except urllib.error.URLError: # Unable to access network
|
||||||
|
return []
|
||||||
|
|
||||||
threads = [threading.Thread(target=download_search_result, args=(elem,)) for elem in partitions]
|
threads = [threading.Thread(target=download_search_result, args=(elem,)) for elem in partitions]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user