mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-16 06:42:10 +00:00
:)
This commit is contained in:
@@ -24,6 +24,7 @@ HOST_ADDRESS = "0.0.0.0"
|
|||||||
PORT_ADDRESS = 5001
|
PORT_ADDRESS = 5001
|
||||||
|
|
||||||
class Librarian(object):
|
class Librarian(object):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
netrc_mod = netrc.netrc(NETRC_FILE)
|
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||||
authTokens = netrc_mod.authenticators("crossref")
|
authTokens = netrc_mod.authenticators("crossref")
|
||||||
@@ -31,24 +32,26 @@ class Librarian(object):
|
|||||||
self.last_search = ""
|
self.last_search = ""
|
||||||
self.limit = 1000
|
self.limit = 1000
|
||||||
|
|
||||||
def search_crossref(self, query):
|
def search_crossref(self, query, uuid):
|
||||||
self.last_search = self.cr.works(query = query, limit = self.limit)
|
self.last_search = self.cr.works(query = query, limit = self.limit)
|
||||||
for item in self.last_search['message']['items']:
|
|
||||||
print("=====")
|
|
||||||
#print (item)
|
|
||||||
print(item['DOI'])
|
|
||||||
print(item['title'])
|
|
||||||
print(item['type'])
|
|
||||||
print("=====")
|
|
||||||
if "container-title" in item:
|
|
||||||
print("This a part of larger release")
|
|
||||||
print(item['container-title'])
|
|
||||||
print (self.last_search['message']['total-results'])
|
|
||||||
#add to sql with UUID
|
#add to sql with UUID
|
||||||
#sql row - title, doi, author, uuid, last retrieved, is_available
|
#sql row - title, doi, author, uuid, last retrieved, is_available
|
||||||
with open("results.json", "x", encoding="UTF-8") as new_file:
|
with open("results.json", "r+", encoding="UTF-8") as data_file:
|
||||||
new_file.seek(0)
|
# First we load existing data into a dict.
|
||||||
json.dump(self.last_search['message']['items'], new_file, indent=4)
|
file_data = json.load(data_file)
|
||||||
|
# Join new_data with file_data inside emp_details
|
||||||
|
summarized_results = []
|
||||||
|
for item in self.last_search['message']['items']:
|
||||||
|
container = "NO"
|
||||||
|
if "container-title" in item:
|
||||||
|
container = "YES"
|
||||||
|
summarized_results.append({"DOI" : item['DOI'], "title": item['title'], "type": item['type'], "container": container})
|
||||||
|
result = {"UUID": uuid, "total_results": self.last_search['message']['total-results'], "on_page" : 1, "summary":summarized_results, "results":self.last_search['message']['items'], }
|
||||||
|
file_data.append(result)
|
||||||
|
data_file.seek(0)
|
||||||
|
# convert back to json.
|
||||||
|
json.dump(file_data, data_file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def check_if_exists(self,page_url):
|
def check_if_exists(self,page_url):
|
||||||
in_scihub_db = True
|
in_scihub_db = True
|
||||||
@@ -78,14 +81,23 @@ class Librarian(object):
|
|||||||
if self.check_if_exists(page_url):
|
if self.check_if_exists(page_url):
|
||||||
return page_url
|
return page_url
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def answer_query(self, uuid, query):
|
def answer_query(self, uuid, query):
|
||||||
#Search sql for UUID
|
#Search sql for UUID
|
||||||
#SQL SELECT * FROM RESULTS WHERE UUID = uuid
|
#SQL SELECT * FROM RESULTS WHERE UUID = uuid
|
||||||
uuid_found = True
|
uuid_found = False
|
||||||
|
with open("results.json", "r", encoding="UTF-8") as new_file:
|
||||||
|
#tu logika komunikacji z SQL i cała logika związana z wyszukaniem
|
||||||
|
#ale tymczasowo plik
|
||||||
|
database = json.load(new_file)
|
||||||
|
for item in database:
|
||||||
|
if item["UUID"]:
|
||||||
|
print item["UUID"]
|
||||||
|
uuid_found = True
|
||||||
if uuid_found:
|
if uuid_found:
|
||||||
return self.last_search
|
return self.last_search
|
||||||
|
self.search_crossref(query=query, uuid=uuid)
|
||||||
|
|
||||||
self.search_crossref(query)
|
|
||||||
#example not exists
|
#example not exists
|
||||||
#sample_non_existing_page_url = "https://sci-hub.se/10.4324/9781003006237"
|
#sample_non_existing_page_url = "https://sci-hub.se/10.4324/9781003006237"
|
||||||
#sample usage to download
|
#sample usage to download
|
||||||
@@ -93,7 +105,6 @@ class Librarian(object):
|
|||||||
#print(cl.download(sample_existing_page_url))
|
#print(cl.download(sample_existing_page_url))
|
||||||
#cl.search_crossref("BDSM")
|
#cl.search_crossref("BDSM")
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
def flask_debug():
|
def flask_debug():
|
||||||
"""
|
"""
|
||||||
@@ -111,7 +122,7 @@ def waitress_run():
|
|||||||
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
|
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
|
||||||
|
|
||||||
@app.route("/query", methods=["POST"])
|
@app.route("/query", methods=["POST"])
|
||||||
def update_music_list():
|
def query_database():
|
||||||
"""
|
"""
|
||||||
The function `update_music_list` receives a POST request with a JSON payload, logs the received
|
The function `update_music_list` receives a POST request with a JSON payload, logs the received
|
||||||
item, adds it to a music file list, and returns a success message along with the updated record.
|
item, adds it to a music file list, and returns a success message along with the updated record.
|
||||||
@@ -127,9 +138,6 @@ def update_music_list():
|
|||||||
app.logger.info(record["UUID"])
|
app.logger.info(record["UUID"])
|
||||||
|
|
||||||
cl = Librarian()
|
cl = Librarian()
|
||||||
with open("results.json", "r", encoding="UTF-8") as new_file:
|
|
||||||
#tu logika komunikacji z SQL i cała logika związana z wyszukaniem
|
|
||||||
cl.last_search = json.load(new_file)
|
|
||||||
|
|
||||||
answer_data = cl.last_search
|
answer_data = cl.last_search
|
||||||
return_data = (
|
return_data = (
|
||||||
@@ -147,7 +155,6 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
for worker in threads:
|
for worker in threads:
|
||||||
worker.start()
|
worker.start()
|
||||||
|
|
||||||
for worker in threads:
|
for worker in threads:
|
||||||
worker.join()
|
worker.join()
|
||||||
|
|
||||||
|
|||||||
-161287
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user