Exemplo n.º 1
0
 def test_read_metrics_new_author(self):
     myAuth = ElsAuthor(uri = self.auth_uri)
     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 readAllDocsFromAuthor(self, authorID='7004367821'):
     ## Read all documents for example author, then write to disk
     my_auth = ElsAuthor(
         uri='https://api.elsevier.com/content/author/author_id/' +
         authorID)
     if my_auth.read_docs(self.client):
         print("my_auth.doc_list has " + str(len(my_auth.doc_list)) +
               " items.")
         my_auth.write_docs()
     else:
         print("Read docs for author failed.")
Exemplo n.º 3
0
def auth_id_query(auth_id):

    my_auth = ElsAuthor(uri='https://api.elsevier.com/content/author/author_id/%s' % (auth_id))
    # Read author data, then write to disk
    if my_auth.read(client):
        try:
            return my_auth.data['author-profile']['affiliation-history']['affiliation']
        except KeyError:
            print("Query results for '%s' were not structured correctly." % (auth_id))
            # print(my_auth.data['author-profile'])
    else:
        print ("Read author failed.")
 def readElsevierAuthor(self, authorID='7004367821'):
     ## Author example
     # Initialize author with uri
     my_auth = ElsAuthor(
         uri='https://api.elsevier.com/content/author/author_id/' +
         authorID)
     # Read author data, then write to disk
     if my_auth.read(self.client):
         print("my_auth.full_name: ", my_auth.full_name)
         my_auth.write()
     else:
         print("Read author failed.")
def initAuthor(author_id):
    # Initialize author with uri
    my_auth = ElsAuthor(
        uri='https://api.elsevier.com/content/author/author_id/{}'.format(
            author_id))
    print('https://api.elsevier.com/content/author/author_id/{}'.format(
        author_id))
    # Read author data, then write to disk
    if my_auth.read(client):
        print('OR AU-ID("{}” {})'.format(
            my_auth.data['author-profile']['preferred-name']['indexed-name'],
            author_id))
        return my_auth.data['author-profile']['preferred-name']['indexed-name']
    else:
        print("Read author failed.")
Exemplo n.º 6
0
def get_author(author_id):
    """
    Retrieves an author

    :param author_id:
    :param api_key:
    :return:
    """
    logger.info(f'Retrieving author {author_id}')
    api_key = key_manager.get_key('author')
    client = elsclient.ElsClient(api_key)
    author = ElsAuthor(author_id=author_id)
    if not author.read(client):
        logger.error("[!]Read author failed: %s", author_id)
    author.data['_id'] = author.data['coredata']['dc:identifier'].split(':')[1]
    author.data['last_modified'] = datetime.now()
    return author.data
Exemplo n.º 7
0
def author_score(fname, lname):
    client = elsevier_auth()

    the_zip = zip(fname, lname)
    num = len(fname)
    count = 0
    total = 0
    score = 0

    for first, last in the_zip:
        start = time.time()
        print(first, last)
        myDocSrch = ElsSearch(
            'AUTHLASTNAME(' + last + ') AND AUTHFIRST(' + first + ')',
            'author')
        myDocSrch.execute(client)

        for x in myDocSrch.results:
            try:
                a_id = x['dc:identifier']
            except:
                continue
            auth_id = a_id.replace('AUTHOR_ID:', '')

            author = ElsAuthor(author_id=auth_id)
            if (author.read_metrics(client)):
                h_index = author.data['h-index']
                score += h_index
                print(first, last, " ID:", auth_id, " h-index:", h_index)
            else:
                print("no data")
                score += 0

        end = time.time()
        diff = end - start
        total += diff
        count += 1
        num -= 1
        avg = total / count
        est = (num * avg) / 60
        print("time used for this author:", end - start, "s")
        print(num, "authors, estimated time left:", est, "minutes")
        print()
    return score
Exemplo n.º 8
0
def getInfoAboutTeacher(person):
    # Load configuration
    con_file = open(SCOPUS_CREDENTIAL_FILE)
    config = json.load(con_file)
    con_file.close()

    # Initialize client
    client = ElsClient(config['apikey'])
    client.inst_token = config['insttoken']

    # Initialize author with uri
    my_auth = ElsAuthor(
        uri='https://api.elsevier.com/content/author/author_id/' +
        str(person.scopusId))
    # Read author data, then write to disk
    if my_auth.read(client):
        return my_auth.data['coredata']
    else:
        print("Read author failed.")
Exemplo n.º 9
0
def get_author_by_id(client, author):
    author_data = {}

    my_auth = ElsAuthor(
        uri=f"https://api.elsevier.com/content/author/author_id/{author}")

    if my_auth.read(client):
        my_auth.read_metrics(client)
        my_auth.read_docs(client)

        field_str = ""
        field_list = []
        for area in my_auth.data['subject-areas']['subject-area']:
            field_str += f"{area['$']} | "
            field_list.append(area['$'])

        author_data['name'] = my_auth.full_name
        author_data['url'] = my_auth.data['coredata']['link'][0]['@href']
        author_data['h-index'] = my_auth.data['h-index']
        author_data['docs'] = my_auth.data['coredata']['document-count']
        author_data['cit'] = my_auth.data['coredata']['citation-count']
        author_data['fields'] = field_list
        author_data['pub-range'] = my_auth.data['author-profile'][
            'publication-range']
        try:
            author_data['affiliation'] = {
                'name':
                my_auth.data['author-profile']['affiliation-current']
                ['affiliation']['ip-doc']['preferred-name']['$'],
                'country':
                my_auth.data['author-profile']['affiliation-current']
                ['affiliation']['ip-doc']['address']['country'],
                'url':
                my_auth.data['author-profile']['affiliation-current']
                ['affiliation']['ip-doc']['org-URL']
            }
        except KeyError:
            author_data['affiliation'] = {'name': '', 'country': '', 'url': ''}

        # print(author_data)

        return author_data

    else:
        print("Read author failed.")
Exemplo n.º 10
0
class TestElsAuthor:
    """Test author object functionality"""
    
    ## 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"""
        myAuth = ElsAuthor(uri = self.auth_uri)
        assert myAuth.uri == self.auth_uri
        
    def test_init_auth_id_int(self):
        """ Test case: uri is set correctly during initialization with author id as integer"""
        myAuth = ElsAuthor(author_id = self.auth_id_int)
        assert myAuth.uri == self.auth_uri
        
    def test_init_auth_id_str(self):
        """ Test case: uri is set correctly during initialization with author id as string"""
        myAuth = ElsAuthor(author_id = self.auth_id_str)
        assert myAuth.uri == self.auth_uri
        
    ## Test reading/writing author profile data
    bad_client = ElsClient("dummy")
    good_client = ElsClient(config['apikey'], inst_token = config['insttoken'])
    good_client.local_dir = str(test_path)

    myAuth = ElsAuthor(uri = auth_uri)
    
    def test_read_good_bad_client(self):
        """Test case: using a well-configured client leads to successful read
            and using a badly-configured client does not."""
        assert self.myAuth.read(self.bad_client) == False
        assert self.myAuth.read(self.good_client) == True

    def test_json_to_dict(self):
        """Test case: the JSON read by the author object from the API is parsed
            into a Python dictionary"""
        assert type(self.myAuth.data) == dict
        
    def test_name_getter(self):
        """Test case: the full name attribute is returned as a non-empty string"""
        assert (type(self.myAuth.full_name) == str and self.myAuth.full_name != '')
        
    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()
        assert len(self.myAuth.doc_list) > 0
        ## TODO: once author metrics inconsistency is resolved, change to: 
        # assert len(self.myAuth.doc_list) == int(self.myAuth.data['coredata']['document-count'])
        
    def test_read_metrics_new_author(self):
        myAuth = ElsAuthor(uri = self.auth_uri)
        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'])
Exemplo n.º 11
0
#client.inst_token = config['insttoken']

# Iniciando para acessar o Fishbase
from requests import get

# seguindo o método DRY vamos importar nossas rotinas do modulo fishbase
# primeiro vamos incluir como 
import sys
sys.path.append('./modules')

#import fishbase
#h = fishbase.host

## Author example
# Initialize author with uri
my_auth = ElsAuthor(
        uri = 'https://api.elsevier.com/content/author/author_id/7004367821')
# Read author data, then write to disk
if my_auth.read(client):
    print ("my_auth.full_name: ", my_auth.full_name)
    my_auth.write()
else:
    print ("Read author failed.")

## Affiliation example
# Initialize affiliation with ID as string
my_aff = ElsAffil(affil_id = '60101411')
if my_aff.read(client):
    print ("my_aff.name: ", my_aff.name)
    my_aff.write()
else:
    print ("Read affiliation failed.")
Exemplo n.º 12
0
auth_srch.execute(client)
aid = auth_srch.results[0]['dc:identifier']
aid = aid[-11:]
auth_srch.results[0]['preferred-name']

getit = 'http://api.elsevier.com/content/search/author?query=AUTHLASTNAME%28Torney%29&apiKey=' + config[
    'apikey']
getit = 'http://api.elsevier.com/content/search/author?co-author=24588214300&apiKey=' + config[
    'apikey']
co - author = 'AUTHOR_ID:24588214300'
aa = requests.get(getit)
bb = aa.json()

hello = pd.DataFrame.from_dict(bb, orient='index')
my_auth = ElsAuthor(
    uri=
    'http://api.elsevier.com/content/search/author?query=AUTHLASTNAME%28Torney%29'
)

## Author example
# Initialize author with uri
my_auth = ElsAuthor(
    uri='https://api.elsevier.com/content/author/author_id/7004367821')
# Read author data, then write to disk
if my_auth.read(client):
    print("my_auth.full_name: ", my_auth.full_name)
    my_auth.write()
else:
    print("Read author failed.")

## Affiliation example
# Initialize affiliation with ID as string
Exemplo n.º 13
0
len(scopus_urls['URL'].unique())

# scopus_urls_back = scopus_urls
#scopus_urls_back.to_csv('scopus_urls.csv', index=False)

# ---------------------------------- author subjects ------------------------------

urls_filepath = 'scopus_urls_no_affil_sub.csv'
scopus_urls = pd.read_csv(urls_filepath, error_bad_lines=False)
scopus_urls.fillna(-1, inplace=True)

#url = scopus_urls['URL'][0]
subjects = []
for url in scopus_urls['URL']:
    if not (url == -1):
        my_auth = ElsAuthor(uri=url)
        if my_auth.read(client):
            print("Retrieving ", my_auth.full_name)
        else:
            print("Read author failed.")
        try:
            for item in my_auth.data['subject-areas']['subject-area']:
                subjects.append([my_auth.full_name, item['$']])
            print(my_auth.full_name + ': Subjects pulled successfully')
        except:
            print(my_auth.full_name + ': No subjects identified')

subjects_edgelist = pd.DataFrame(data=subjects, columns=['Name', 'Subject'])
#subjects_edgelist.to_csv('subjects_edgelist_no_affil_full.csv', index=False)

len(subjects_edgelist['Name'].unique())
Exemplo n.º 14
0
from elsapy.elsdoc import FullDoc, AbsDoc
from elsapy.elssearch import ElsSearch
import json

## Load configuration
con_file = open("config.json")
config = json.load(con_file)
con_file.close()

## Initialize client
client = ElsClient(config['apikey'])
client.inst_token = config['insttoken']

## Author example
# Initialize author with uri
my_auth = ElsAuthor(
    uri='https://api.elsevier.com/content/author/author_id/15036893200')
# Read author data, then write to disk
if my_auth.read(client):
    print("my_auth.full_name: ", my_auth.full_name)
    my_auth.write()
else:
    print("Read author failed.")

# ## Affiliation example
# # Initialize affiliation with ID as string
# my_aff = ElsAffil(affil_id = '60101411')
# if my_aff.read(client):
#     print ("my_aff.name: ", my_aff.name)
#     my_aff.write()
# else:
#     print ("Read affiliation failed.")
Exemplo n.º 15
0
 def test_init_uri(self):
     """ Test case: uri is set correctly during initialization with uri"""
     myAuth = ElsAuthor(uri = self.auth_uri)
     assert myAuth.uri == self.auth_uri
Exemplo n.º 16
0
 def test_init_auth_id_str(self):
     """ Test case: uri is set correctly during initialization with author id as string"""
     myAuth = ElsAuthor(author_id = self.auth_id_str)
     assert myAuth.uri == self.auth_uri
Exemplo n.º 17
0
con_file.close()

## Initialize client
client = ElsClient(config['apikey'])
# client.inst_token = config['insttoken']

## Author example
# Initialize author with uri
URI = "https://krr.cs.vu.nl/"

data = {"data": "24.3"}
data_json = json.dumps(data)

headers = {'Accept': 'application/json'}

my_auth = ElsAuthor(
    uri='https://api.elsevier.com/content/author/author_id/7004322609')

#data from Elsevier
# resp = client.exec_request('https://api.elsevier.com/content/search/scopus?query=all(7004322609)&apiKey=ff61921fc97787106a446daa9dc3827b')

resp = client.exec_request(
    'https://api.elsevier.com/content/search/author?query=authlast(Harmelen)&apiKey=7f59af901d2d86f78a1fd60c1bf9426a'
)

data = resp  #data from scopus

#data from JSON file
# with open('data_scopus_author.json') as json_file:
#     data_json_file = json.load(json_file)

# data = data_json_file       #data from JSON file