Exemplo de Uso Api
Exemplo de Uso Api
Como posso obter mais de 5.000/6.000 resultados através das APIs Scopus/ScienceDirect?
O número de resultados que podem ser recuperados por meio da API ScienceDirect Query é 6.000.
Essa limitação não é específica de nenhuma chave de API ou cliente, mas é um artefato da tecnologia
de pesquisa de back-end usada para esta API.
Para assinantes Scopus, esta restrição não se aplica mais à API Scopus Search. Por favor, revise o
seguinte exemplo:
https://api.elsevier.com/content/search/scopus?query=title-abs-key(mars)
<opensearch:totalResults>38557</opensearch:totalResults>
<opensearch:startIndex>0</opensearch
<opensearch:itemsPerPage>25</opensearch:itemsPerPage>
<opensearch:Query role="request" searchTerms="TITLE-ABS-KEY(mars)"
Para iterar todos os 38.000 resultados, usa-se o parâmetro cursor (documentado nas especificações da
API Scopus Search ).
https://api.elsevier.com/content/search/scopus?query=title-abs-key(mars)&cursor=*&count=25
Além disso, a resposta também contém uma solicitação de API codificada em URL completa com o
valor for next pré-preenchido em cursor :
Usando o próximo valor do cursor ou URL, pode-se recuperar os próximos 25 resultados. O processo
pode ser repetido até que todos os 38.000 resultados tenham sido recuperados.
EXEMPLO DE USO
"""Test cases for elsapy"""
## TODO:
## - break down in modules (test suites) for each class to allow faster unit-testing
conFile = open("config.json")
config = json.load(conFile)
conFile.close()
## Set local path for test data and ensure it's clean
if not test_path.exists():
test_path.mkdir()
else:
file_list = list(test_path.glob('*'))
## TODO: write recursive function that also identifies and clears out child directories
for e in file_list:
if e.is_file():
e.unlink()
class util:
def file_exist_with_id(id):
"""Test case: exactly one local file exist with given ID in the filename"""
if len(list(test_path.glob('*' + id +'*'))) == 1:
return True
class TestElsClient:
def test_init_apikey_(self):
"""Test case: APIkey and token are set correctly during initialization"""
my_client = ElsClient(config['apikey'])
def test_init_apikey_insttoken(self):
"""Test case: APIkey and insttoken are set correctly during initialization"""
def test_init_apikey_insttoken_path(self):
"""Test case: APIkey, insttoken and local path are set correctly during initialization"""
loc_dir = '\\TEMP'
"""Test case: APIkey and insttoken are set correctly using setters"""
my_client = ElsClient("dummy")
my_client.api_key = config['apikey']
my_client.inst_token = config['insttoken']
class TestElsAuthor:
## Test data
auth_uri = "https://api.elsevier.com/content/author/author_id/55070335500"
auth_id_int = 55070335500
auth_id_str = "55070335500"
## Test initialization
def test_init_uri(self):
""" Test case: uri is set correctly during initialization with uri"""
def test_init_auth_id_int(self):
""" Test case: uri is set correctly during initialization with author id as integer"""
def test_init_auth_id_str(self):
""" Test case: uri is set correctly during initialization with author id as string"""
bad_client = ElsClient("dummy")
good_client.local_dir = str(test_path)
def test_read_good_bad_client(self):
def test_json_to_dict(self):
"""Test case: the JSON read by the author object from the API is parsed
def test_name_getter(self):
def test_write(self):
"""Test case: the author object's data is written to a file with the author
ID in the filename"""
self.myAuth.write()
assert util.file_exist_with_id(self.myAuth.data['coredata']['dc:identifier'].split(':')[1])
def test_read_docs(self):
self.myAuth.read_docs()
def test_read_metrics_new_author(self):
myAuth.read_metrics(self.good_client)
assert (
myAuth.data['coredata']['citation-count'] and
myAuth.data['coredata']['cited-by-count'] and
myAuth.data['coredata']['document-count'] and
myAuth.data['h-index'])
def test_read_metrics_existing_author(self):
self.myAuth.read_metrics(self.good_client)
assert (
self.myAuth.data['coredata']['citation-count'] and
self.myAuth.data['coredata']['cited-by-count'] and
self.myAuth.data['coredata']['document-count'] and
self.myAuth.data['h-index'])
class TestElsAffil:
## Test data
aff_uri = "https://api.elsevier.com/content/affiliation/affiliation_id/60101411"
aff_id_int = 60101411
aff_id_str = "60101411"
## Test initialization
def test_init_uri(self):
""" Test case: uri is set correctly during initialization with uri"""
def test_init_aff_id_int(self):
""" Test case: uri is set correctly during initialization with affiliation id as integer"""
def test_init_aff_id_str(self):
""" Test case: uri is set correctly during initialization with affiliation id as string"""
bad_client = ElsClient("dummy")
good_client.local_dir = str(test_path)
def test_read_good_bad_client(self):
def test_json_to_dict(self):
"""Test case: the JSON read by the author object from the API is parsed
into a Python dictionary"""
def test_name_getter(self):
def test_write(self):
"""Test case: the author object's data is written to a file with the author
ID in the filename"""
self.myAff.write()
assert util.file_exist_with_id(self.myAff.data['coredata']['dc:identifier'].split(':')[1])
def test_read_docs(self):
self.myAff.read_docs()
class TestAbsDoc:
## Test data
abs_uri = "https://api.elsevier.com/content/abstract/scopus_id/84872135457"
scp_id_int = 84872135457
scp_id_str = "84872135457"
## Test initialization
def test_init_uri(self):
""" Test case: uri is set correctly during initialization with uri"""
""" Test case: uri is set correctly during initialization with Scopus id as integer"""
def test_init_scp_id_str(self):
""" Test case: uri is set correctly during initialization with Scopus id as string"""
bad_client = ElsClient("dummy")
good_client.local_dir = str(test_path)
def test_read_good_bad_client(self):
def test_json_to_dict(self):
"""Test case: the JSON read by the abstract document object from the
def test_title_getter(self):
def test_write(self):
"""Test case: the abstract document object's data is written to a file with the Scopus
ID in the filename"""
self.myAbsDoc.write()
assert util.file_exist_with_id(self.myAbsDoc.data['coredata']['dc:identifier'].split(':')[1])
class TestFullDoc:
## Test data
full_pii_uri = "https://api.elsevier.com/content/article/pii/S1674927814000082"
sd_pii = 'S1674927814000082'
full_doi_uri = "https://api.elsevier.com/content/article/doi/10.1016/S1525-1578(10)60571-5"
doi = '10.1016/S1525-1578(10)60571-5'
## Test initialization
def test_init_uri(self):
""" Test case: uri is set correctly during initialization with uri"""
def test_init_sd_pii(self):
""" Test case: uri is set correctly during initialization with ScienceDirect PII"""
def test_init_doi(self):
""" Test case: uri is set correctly during initialization with DOI"""
bad_client = ElsClient("dummy")
good_client.local_dir = str(test_path)
def test_read_good_bad_client(self):
def test_json_to_dict(self):
"""Test case: the JSON read by the full article object from the
def test_title_getter(self):
def test_write(self):
"""Test case: the full article object's data is written to a file with the ID in the filename"""
self.myFullDoc.write()
assert util.file_exist_with_id(
self.myFullDoc.data['coredata']['pii'].replace('-','').replace('(','').replace(')',''))
class TestSearch:
## Test data
base_url = u'https://api.elsevier.com/content/search/'
search_types = [
"index" : "scopus"},
## Test initialization
def test_init_uri(self):
"""Test case: query, index and uri are set correctly during
initialization"""
match_all = True
for i in range(len(self.search_types)):
if (self.searches[i].query != self.search_types[i]['query'] or
self.searches[i].index != self.search_types[i]['index'] or
self.searches[i].uri != (self.base_url +
self.search_types[i]['index'] +
'?query=' +
url_encode(self.search_types[i]['query']))):
match_all = False
def test_execution(self):
search.execute(self.good_client)
assert True