Final version before tests

This commit is contained in:
2024-04-02 13:15:18 +02:00
parent 17b364524d
commit aa57a51057
2 changed files with 26 additions and 10 deletions
+12 -2
View File
@@ -1,6 +1,7 @@
import re
import logging
import threading
import time
from flask import Flask, jsonify, request
import netrc
import json
@@ -51,7 +52,6 @@ class Librarian(object):
container = "YES"
print(item['title'])
print(item['DOI'])
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)
@@ -89,6 +89,16 @@ class Librarian(object):
if self.check_if_exists(page_url):
return page_url
return None
def refine_query(self, unrefined_reqult):
refined_result = []
for item in unrefined_reqult["summary"]
if item["container"] == "NO":
item_link = f"https://scihub.se/{item["DOI"]}"
if self.check_if_exists(item_link):
refined_result.append(item)
print item_link
time.wait(0.2)
return refined_result
def answer_query(self, query, uuid):
#Search sql for UUID
@@ -111,7 +121,7 @@ class Librarian(object):
if uuid_found:
return self.last_search
self.search_crossref(query=query, uuid=uuid)
return self.last_search
return self.refine_query(self.last_search)
#example not exists
#sample_non_existing_page_url = "https://sci-hub.se/10.4324/9781003006237"