mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
fx
This commit is contained in:
@@ -31,11 +31,10 @@ class Librarian(object):
|
||||
netrc_mod = netrc.netrc(NETRC_FILE)
|
||||
authTokens = netrc_mod.authenticators("crossref")
|
||||
self.cr = Crossref(mailto=authTokens[0])
|
||||
self.last_search = ""
|
||||
self.limit = 200
|
||||
|
||||
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
|
||||
#sql row - title, doi, author, uuid, last retrieved, is_available
|
||||
with open("results.json", "r+", encoding="UTF-8") as data_file:
|
||||
@@ -46,19 +45,20 @@ class Librarian(object):
|
||||
file_data = []
|
||||
# Join new_data with file_data inside emp_details
|
||||
summarized_results = []
|
||||
for item in self.last_search['message']['items']:
|
||||
for item in search_result_from_cr['message']['items']:
|
||||
container = "NO"
|
||||
if "container-title" in item:
|
||||
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'], }
|
||||
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)
|
||||
print("Saving")
|
||||
data_file.seek(0)
|
||||
# convert back to json.
|
||||
json.dump(file_data, data_file, indent=4)
|
||||
return result
|
||||
|
||||
|
||||
def check_if_exists(self,page_url):
|
||||
@@ -117,11 +117,11 @@ class Librarian(object):
|
||||
if item["UUID"] == uuid:
|
||||
print (item["UUID"])
|
||||
uuid_found = True
|
||||
self.last_search = item
|
||||
if uuid_found:
|
||||
return self.last_search
|
||||
self.search_crossref(query=query, uuid=uuid)
|
||||
return self.refine_query(self.last_search)
|
||||
self.refine_query(item)
|
||||
|
||||
if not uuid_found:
|
||||
answer = self.search_crossref(query=query, uuid=uuid)
|
||||
return self.refine_query(answer)
|
||||
|
||||
#example not exists
|
||||
#sample_non_existing_page_url = "https://sci-hub.se/10.4324/9781003006237"
|
||||
|
||||
Reference in New Issue
Block a user