Skip to content

Commit

Permalink
Add series function
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorrell committed Jan 25, 2025
1 parent ddd0492 commit b9dd343
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions ames/harvesters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from .caltechauthors import get_request_comments
from .caltechauthors import get_request_id_title
from .caltechauthors import get_publisher
from .caltechauthors import get_series_records
27 changes: 27 additions & 0 deletions ames/harvesters/caltechauthors.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ def get_group_records(group_identifier, test=False):
return hits


def get_series_records(series_name, test=False, token=None):
if test:
url = "https://authors.caltechlibrary.dev/api/records"
else:
url = "https://authors.library.caltech.edu/api/records"

query = f'?q=custom_fields.caltech%5C%3Aseries%3D"{series_name}"'

if token:
headers = {
"Authorization": "Bearer %s" % token,
"Content-type": "application/json",
}

url = url + query
response = requests.get(url)
total = response.json()["hits"]["total"]
pages = math.ceil(int(total) / 1000)
hits = []
for c in range(1, pages + 1):
chunkurl = f"{url}&size=1000&page={c}"
response = requests.get(chunkurl).json()
hits += response["hits"]["hits"]

return hits


def get_restricted_records(token, test=False):
if test:
url = "https://authors.caltechlibrary.dev/api/records"
Expand Down

0 comments on commit b9dd343

Please sign in to comment.