mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-19 16:22:10 +00:00
Fixes!
This commit is contained in:
@@ -9,9 +9,6 @@ from json.decoder import JSONDecodeError
|
||||
from platform import uname
|
||||
from sys import platform
|
||||
from urllib.request import urlopen
|
||||
import asyncio
|
||||
from queue import Queue
|
||||
from threading import Thread
|
||||
from habanero import Crossref
|
||||
from waitress import serve
|
||||
|
||||
@@ -76,29 +73,15 @@ class Librarian(object):
|
||||
#TODO: Później robimy tak że query jest najpierw sprawdzane w sql - i dawane jako "zapisana lokalna kopia"
|
||||
#TODO: Paginacja - najpierw hity z pliku, potem na końcu to co nie zwróciło żadnych hitów - i to dopiero można crawlerem sprawdzić
|
||||
|
||||
def check_dois_in_file(self, file_name, dois, out_queue):
|
||||
with open(f'{DATABASE_PATH}{file_name}', "r+", encoding=ENCODING) as file:
|
||||
while True:
|
||||
# Get next line from file
|
||||
line = file.readline()
|
||||
if line == dois:
|
||||
return True
|
||||
# if line is empty
|
||||
# end of file is reached
|
||||
if not line:
|
||||
return False
|
||||
|
||||
def check_dois_in_local_db(self, dois):
|
||||
_sentinel = object()
|
||||
chunk_list = []
|
||||
q = Queue()
|
||||
#odwolanie do search_bota
|
||||
|
||||
for file in chunk_list:
|
||||
t = Thread(target = self.check_dois_in_file, args = (file ,dois, q))
|
||||
t.start()
|
||||
q.put(_sentinel)
|
||||
result = False
|
||||
return result
|
||||
|
||||
def check_if_exists(self, page_url):
|
||||
|
||||
def check_if_exists_brute_force(self, page_url):
|
||||
if not page_url.startswith(("http:", "https:")):
|
||||
raise ValueError("URL must start with 'http:' or 'https:'")
|
||||
# trunk-ignore(bandit/B310)
|
||||
@@ -107,23 +90,31 @@ class Librarian(object):
|
||||
text = data.decode("utf-8")
|
||||
for line in text.splitlines():
|
||||
if re.match(r".*Unfortunately, Sci-Hub doesn't have the requested document.*", line):
|
||||
return None
|
||||
return True
|
||||
if m := re.match(r".*<embed type=\"application.pdf\"\s*src=\"(.*\.pdf)",line):
|
||||
return "https:" + str(m.group(1))
|
||||
return None
|
||||
direct_download_link = "https:" + str(m.group(1))
|
||||
print (direct_download_link)
|
||||
return True
|
||||
return False
|
||||
|
||||
def provide_sci_hub_link(self, page_url):
|
||||
if self.check_if_exists(page_url):
|
||||
return page_url
|
||||
return None
|
||||
|
||||
def refine_query(self, unrefined_reqult):
|
||||
def check_if_exists(self, doi, brute_force = False):
|
||||
self.check_dois_in_local_db(doi)
|
||||
if brute_force:
|
||||
item_link = "https://sci-hub.se/" + doi
|
||||
self.check_if_exists_brute_force(item_link)
|
||||
return False
|
||||
|
||||
def refine_query(self, unrefined_reqult, brute_force = False):
|
||||
print("Refine result")
|
||||
refined_result = []
|
||||
for item in unrefined_reqult["summary"]:
|
||||
if item["container"] == "NO" and item["title"]:
|
||||
item_link = "https://sci-hub.se/" + str(item['DOI'])
|
||||
if self.check_if_exists(item_link):
|
||||
if self.check_if_exists(str(item["DOI"])):
|
||||
refined_result.append(item)
|
||||
print ("HIT")
|
||||
print(item["title"])
|
||||
@@ -150,6 +141,7 @@ class Librarian(object):
|
||||
if item["UUID"] == uuid:
|
||||
print (item["UUID"])
|
||||
uuid_found = True
|
||||
#TODO: THREAD IT
|
||||
return self.refine_query(item)
|
||||
|
||||
if not uuid_found:
|
||||
|
||||
Reference in New Issue
Block a user