Skip to content

Commit

Permalink
Merge pull request #1021 from sbillinge/patch_read_lists
Browse files Browse the repository at this point in the history
started process to get formatted refs only once and not every time in the loop
  • Loading branch information
sbillinge authored Jul 21, 2023
2 parents 83c79ea + ef37baa commit 66c1c15
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
23 changes: 23 additions & 0 deletions news/patch_read_lists.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Changed how the reading-list builder fetches the references from Crossref so that it only fetches each needed reference once.

**Security:**

* <news item>
28 changes: 19 additions & 9 deletions regolith/builders/readinglistsbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ def latex(self):
"""Render latex template"""
rc = self.rc

# build the collection of formatted references so that we only go
# and fetch the formatted references once per doi
dois, formatted_refs = [], {}
for rlist in self.gtx["reading_lists"]:
for paper in rlist['papers']:
dois.append(paper.get('doi', ''))
dois = list(set(dois))
for item in ['tbd', '']:
if item in dois:
dois.remove('tbd')
dois.remove('')
for doi in dois:
ref_and_date = get_formatted_crossref_reference(doi)
formatted_refs.update({doi: ref_and_date})

# loop through the reading lists to build the files
for rlist in self.gtx["reading_lists"]:
listid = rlist["_id"]
outfile_bib = listid
Expand All @@ -53,15 +69,9 @@ def latex(self):
doi = None
url = paper.get('url')
if doi:
# if rc.verbose:
# print(f"getting {doi} for {paper.get('tite')}")
ref, ref_date = get_formatted_crossref_reference(doi)
# if rc.verbose:
# try:
# print(f"got ref: {ref}")
# except:
# print("obtained ref but print error")
paper.update({'reference': ref, 'ref_date': ref_date, 'n': n, 'label': 'DOI'})
paper.update({'reference': formatted_refs.get(doi)[0],
'ref_date': formatted_refs.get(doi)[1],
'n': n, 'label': 'DOI'})
n += 1
elif url:
paper['doi'] = url
Expand Down
2 changes: 1 addition & 1 deletion regolith/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ def get_formatted_crossref_reference(doi):

authorlist = [
f"{a['given'].strip()} {a['family'].strip()}"
for a in article.get('message').get('author')]
for a in article.get('message',{}).get('author','')]
try:
journal = \
article.get('message').get('short-container-title')[0]
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"grantreport",
"resume",
"review-man",
# reading-lists need tests for this
"reimb"
]
db_srcs = ["mongo", "fs"]
Expand Down

0 comments on commit 66c1c15

Please sign in to comment.