mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-19 08:12:09 +00:00
fx
This commit is contained in:
@@ -31,11 +31,10 @@ class Librarian(object):
|
|||||||
netrc_mod = netrc.netrc(NETRC_FILE)
|
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||||
authTokens = netrc_mod.authenticators("crossref")
|
authTokens = netrc_mod.authenticators("crossref")
|
||||||
self.cr = Crossref(mailto=authTokens[0])
|
self.cr = Crossref(mailto=authTokens[0])
|
||||||
self.last_search = ""
|
|
||||||
self.limit = 200
|
self.limit = 200
|
||||||
|
|
||||||
def search_crossref(self, query, uuid):
|
def search_crossref(self, query, uuid):
|
||||||
self.last_search = self.cr.works(query = query, limit = self.limit)
|
search_result_from_cr = self.cr.works(query = query, limit = self.limit)
|
||||||
#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", "r+", encoding="UTF-8") as data_file:
|
with open("results.json", "r+", encoding="UTF-8") as data_file:
|
||||||
@@ -46,19 +45,20 @@ class Librarian(object):
|
|||||||
file_data = []
|
file_data = []
|
||||||
# Join new_data with file_data inside emp_details
|
# Join new_data with file_data inside emp_details
|
||||||
summarized_results = []
|
summarized_results = []
|
||||||
for item in self.last_search['message']['items']:
|
for item in search_result_from_cr['message']['items']:
|
||||||
container = "NO"
|
container = "NO"
|
||||||
if "container-title" in item:
|
if "container-title" in item:
|
||||||
container = "YES"
|
container = "YES"
|
||||||
print(item['title'])
|
print(item['title'])
|
||||||
print(item['DOI'])
|
print(item['DOI'])
|
||||||
summarized_results.append({"DOI" : item['DOI'], "title": item['title'], "type": item['type'], "container": container})
|
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'], }
|
result = {"UUID": uuid, "total_results": search_result_from_cr['message']['total-results'], "on_page" : 1, "summary":summarized_results, "results":search_result_from_cr['message']['items'], }
|
||||||
file_data.append(result)
|
file_data.append(result)
|
||||||
print("Saving")
|
print("Saving")
|
||||||
data_file.seek(0)
|
data_file.seek(0)
|
||||||
# convert back to json.
|
# convert back to json.
|
||||||
json.dump(file_data, data_file, indent=4)
|
json.dump(file_data, data_file, indent=4)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def check_if_exists(self,page_url):
|
def check_if_exists(self,page_url):
|
||||||
@@ -117,11 +117,11 @@ class Librarian(object):
|
|||||||
if item["UUID"] == uuid:
|
if item["UUID"] == uuid:
|
||||||
print (item["UUID"])
|
print (item["UUID"])
|
||||||
uuid_found = True
|
uuid_found = True
|
||||||
self.last_search = item
|
self.refine_query(item)
|
||||||
if uuid_found:
|
|
||||||
return self.last_search
|
if not uuid_found:
|
||||||
self.search_crossref(query=query, uuid=uuid)
|
answer = self.search_crossref(query=query, uuid=uuid)
|
||||||
return self.refine_query(self.last_search)
|
return self.refine_query(answer)
|
||||||
|
|
||||||
#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"
|
||||||
|
|||||||
Reference in New Issue
Block a user