Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion elsapy/elsdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import log_util
from .elsentity import ElsEntity
from urllib import parse

logger = log_util.get_logger(__name__)

Expand Down Expand Up @@ -85,4 +86,72 @@ def read(self, els_client = None):
if super().read(self.__payload_type, els_client):
return True
else:
return False
return False


class ElsAbstract(ElsEntity):
"""A document with abstract and other information such as authors. It's retrieved from the abstract service"""

# static variables
__payload_type = u'abstracts-retrieval-response'
__uri_base = u'https://api.elsevier.com/content/abstract/'

@property
def authors(self):
"""Get the document's authors"""
return self.data['authors']['author']

def __init__(self, uri='', scopus_id='', doi='', params={}):
"""Initializes a document given a Scopus ID."""
if uri and not scopus_id and not doi:
s_uri = uri
elif scopus_id and not uri and not doi:
s_uri = self.__uri_base + 'scopus_id/' + str(scopus_id)
if params:
s_uri += '?' + parse.urlencode(params)
elif doi and not uri and not scopus_id:
s_uri = self.__uri_base + 'doi/' + str(doi)
if params:
s_uri += '?' + parse.urlencode(params)
else:
raise ValueError('Multiple identifiers specified; just need one.')
if s_uri is None:
raise ValueError('No URI, Scopus ID or DOI specified')
super().__init__(s_uri)

def read(self, els_client=None):
"""Reads the JSON representation of the document from ELSAPI.
Returns True if successful; else, False."""
if super().read(self.__payload_type, els_client):
return True
else:
return False


class ElsSerial(ElsEntity):
"""A serial(Journal, conference proceeding etc.) in Scopus"""

# static variables
__payload_type = u'serial-metadata-response'
__uri_base = u'http://api.elsevier.com/content/serial/title'

# constructors
def __init__(self, uri='', scopus_id='', params={}):
if uri and not scopus_id:
s_uri = uri
super().__init__(uri)
elif scopus_id and not uri:
params['source-id'] = scopus_id
s_uri = self.__uri_base + '?' + parse.urlencode(params)
elif not uri and not scopus_id:
raise ValueError('No URI or scopus id specified')
else:
raise ValueError('Both URI and scopus id specified; just need one.')
print(s_uri)
super().__init__(s_uri)

def read(self, els_client=None):
if super().read(self.__payload_type, els_client):
return True
else:
return False
6 changes: 5 additions & 1 deletion elsapy/elsprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def __init__(self, uri = '', affil_id = ''):
@property
def name(self):
"""Gets the affiliation's name"""
return self.data["affiliation-name"];
return self.data["affiliation-name"]

@property
def parent(self):
return self.data.get('institution-profile', {}).get('@parent', None)

# modifier functions
def read(self, els_client = None):
Expand Down
28 changes: 28 additions & 0 deletions elsapy/elssearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* https://api.elsevier.com"""

from . import log_util
from urllib import parse

logger = log_util.get_logger(__name__)

Expand Down Expand Up @@ -87,3 +88,30 @@ def hasAllResults(self):
"""Returns true if the search object has retrieved all results for the
query from the index (i.e. num_res equals tot_num_res)."""
return (self.num_res is self.tot_num_res)


class ElsSerialTitleSearch(ElsSearch):
"""Represents a search to the serial title search"""

__base_url = u'https://api.elsevier.com/content/serial/title'

def __init__(self, title, params={}):
super.__init__()
"""Initializes a search object with a query and target index."""
self._title = title
self._params = params
# There is a bug in scopus API. Params are dropped in links if they appear in front of the 'query' param.
# Make sure query appear the first in the query string in the URL
self._uri = self.__base_url + '?' + parse.urlencode({'title': title, **params})

@property
def title(self):
return self._title

@title.setter
def title(self, title):
self._title = title

def execute(self, els_client=None):
api_response = els_client.exec_request(self._uri)
self._results = api_response['serial-metadata-response']['entry']
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name = 'elsapy',
version = version,
description = "A Python module for use with Elsevier's APIs: Scopus, ScienceDirect, others - see https://api.elsevier.com",
long_description = "See https://github.com/ElsevierDev/elsapy for the latest information / background to this project."
long_description = "See https://github.com/ElsevierDev/elsapy for the latest information / background to this project.",
author = 'Elsevier, Inc.',
author_email = 'integrationsupport@elsevier.com',
url = 'https://github.com/ElsevierDev/elsapy',
Expand Down