diff --git a/elsapy/elsdoc.py b/elsapy/elsdoc.py index 453d10c..3966b9d 100644 --- a/elsapy/elsdoc.py +++ b/elsapy/elsdoc.py @@ -6,6 +6,7 @@ from . import log_util from .elsentity import ElsEntity +from urllib import parse logger = log_util.get_logger(__name__) @@ -85,4 +86,72 @@ def read(self, els_client = None): if super().read(self.__payload_type, els_client): return True else: - return False \ No newline at end of file + 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 diff --git a/elsapy/elsprofile.py b/elsapy/elsprofile.py index bac0c9c..14ea5db 100644 --- a/elsapy/elsprofile.py +++ b/elsapy/elsprofile.py @@ -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): diff --git a/elsapy/elssearch.py b/elsapy/elssearch.py index 7b832ee..e6c740b 100644 --- a/elsapy/elssearch.py +++ b/elsapy/elssearch.py @@ -5,6 +5,7 @@ * https://api.elsevier.com""" from . import log_util +from urllib import parse logger = log_util.get_logger(__name__) @@ -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'] diff --git a/setup.py b/setup.py index 3d44240..181005a 100644 --- a/setup.py +++ b/setup.py @@ -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',