# out of order
import requests
MAX_REQUEST_SIZE = 500
def chunks(lst, chunk_size=MAX_REQUEST_SIZE):
"""Splits a longer list to respect batch size"""
for i in range(0, len(lst), chunk_size):
yield lst[i : i + chunk_size]
QUERY = f'https://api.semanticscholar.org/graph/v1/paper/batch'
chunk = ['b10ab3b45876dcd75e96feecdd5dee5c9633bc1a', 'a14897448e472a430439e2e24abba637f9db7a27', 'fbbb80bfeb35569ee8473b80aa98c716c4a6b034']
response = requests.post(QUERY, json={'ids': chunk})
print([p['paperId'] for p in response.json()])
> ['b10ab3b45876dcd75e96feecdd5dee5c9633bc1a', 'fbbb80bfeb35569ee8473b80aa98c716c4a6b034', 'a14897448e472a430439e2e24abba637f9db7a27']
chunk = ['1e42f34a97365192e2ed144bbc1cffe90250fa56', 'dafecfed46fa849be587bd3cfcc44dce03b6f96f', 'd4f216955046faeaa0737aa4c6de760e4594d6f4']
response = requests.post(QUERY, json={'ids': chunk})
print([p['paperId'] for p in response.json()])
> ['dafecfed46fa849be587bd3cfcc44dce03b6f96f', '1e42f34a97365192e2ed144bbc1cffe90250fa56']
Similarly, if there is lack of a match in the API, the API should still return something for that entry as opposed to a shorter length list. For example, the bulk Authors query in API still returns None
for unmatched author IDs
QUERY = f'https://api.semanticscholar.org/graph/v1/author/batch'
response = requests.post(QUERY, json={'ids': ['46258841', '999999999', '3328733']})
> response.json()
> [{'authorId': '46258841', 'name': 'Kyle Lo'}, None, {'authorId': '3328733', 'name': 'Luca Soldaini'}]