Exemple #1
0
 def test_set_apikey_insttoken(self):
     """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']
     assert my_client.api_key == config['apikey']
     assert my_client.inst_token == config['insttoken']
Exemple #2
0
def main():
    # Load author ID list
    with open('authors.json', 'r', encoding='utf-8') as fp:
        data = json.load(fp)
        author_list = data['ids']

    ## Load configuration
    with open("config.json") as con_file:
        config = json.load(con_file)

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

    get_metrics(client, author_list)
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.")
Exemple #4
0
def main():
    # Load author names list
    with open('authors.json', 'r', encoding='utf-8') as fp:
        data = json.load(fp)
        search_list = data['names']

    # 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']

    # Run search for each author names in list and get IDs
    auth_id_list = []
    for author in search_list:
        search_query = ""
        if len(author[0]) > 0:
            search_query += f"authfirst({author[0]}) "
        if len(author[1]) > 0:
            search_query += f"authlast({author[1]})"

        auth_srch = ElsSearch(search_query, 'author')
        auth_srch.execute(client)
        print(
            f'\n{author[0]} {author[1]}: {len(auth_srch.results)} results found!\n'
        )

        # If there are more than one author that matches the search, display search results
        if len(auth_srch.results) > 1:
            for i, search_result in enumerate(auth_srch.results):
                first_name = search_result['preferred-name']['given-name']
                surname = search_result['preferred-name']['surname']
                try:
                    affiliation = search_result['affiliation-current'][
                        'affiliation-name']
                    affiliation_country = search_result['affiliation-current'][
                        'affiliation-country']
                except KeyError:
                    affiliation = ''
                    affiliation_country = ''
                print(
                    f"[{i+1}] {first_name} {surname}, {affiliation} ({affiliation_country})"
                )

            # Choose desired author
            desired_author_index = int(input('\nChoose correct author: ')) - 1

        else:
            desired_author_index = 0

        # Get author ID
        desired_author = auth_srch.results[desired_author_index]
        link = desired_author['link'][0]['@href']
        auth_id = desired_author['dc:identifier'].split(':')[1]
        auth_id_list.append(auth_id)

    # Save author ID to JSON
    with open('authors.json', 'w', encoding='utf-8') as fp:
        data = {'ids': auth_id_list, 'names': search_list}
        json.dump(data, fp, indent=4, sort_keys=True)

    print(link)
    print('\n-----------\n')
    print('Grabbing author metrics...')

    get_author_by_id.get_metrics(client, auth_id_list)
Exemple #5
0
from elsapy.elsclient import ElsClient
from elsapy.elsprofile import ElsAuthor, ElsAffil
from elsapy.elsdoc import FullDoc, AbsDoc
from elsapy.elssearch import ElsSearch
import json
import requests
import pandas as pd

## 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']

## Initialize author search object and execute search
auth_srch = ElsSearch('authlast(torney)+AUTHFIRST(colin)', 'author')
auth_srch.execute(client)
print("auth_srch has", len(auth_srch.results), "results.")

auth_srch = ElsSearch('co-author(24588214300)', 'author')
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[
Exemple #6
0
def detailed_auth_query(auth_last, auth_first):

    auth_data = [auth_last, auth_first, '', '']
    print("Searching for author %s, %s" % (auth_last, auth_first))
    # Initialize search object and execute search under the author index
    query = 'authlast(%s)+AND+authfirst(%s)' % (auth_last, auth_first)

    try:
        auth_srch = ElsSearch(query, 'author')
        auth_srch.execute(client, get_all=False)

    except:
        # Load other configuration with new API Key
        con_file = open("config2.json")
        config = json.load(con_file)
        con_file.close()

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

        auth_srch = ElsSearch(query, 'author')
        auth_srch.execute(client, get_all=False)

    if (len(auth_srch.results) == 1):
        print("auth_srch has", len(auth_srch.results), "result.")
    else:
        print("auth_srch has", len(auth_srch.results), "results.")

    # checking if no results at all
    error_message = auth_srch.results[0].get('error')

    if (len(auth_srch.results) > 0):

        if (not error_message):

            print("Into the results...")

            # grabs the author_id from the search data
            for i in range(len(auth_srch.results)):

                try:
                    string_author_id = auth_srch.results[i].get('dc:identifier')
                    # this line cuts the author id string from the end of AUTHOR_ID
                    # to the end of the id digits
                    author_id = string_author_id[10:]
                    print("author_id : %s" % author_id)
                    auth_data[2] = author_id

                except AttributeError:
                    print("Could not extract auth_id field for %s, %s" % (auth_last, auth_first))
                    auth_data[2] = "CNE"

                # grabs the curr_affil from the search data
                # appends it to auth_data
                try:
                    dict_curr_affil = auth_srch.results[i].get('affiliation-current')
                    curr_affil = dict_curr_affil.get('affiliation-name')
                    print("curr_affil : %s" % curr_affil)

                except AttributeError:
                    print("Could not extract curr_affil field for %s, %s" % (auth_last, auth_first))
                    auth_data[3] = "CNE"

                try:
                    # if UR not current affil go on and search history
                    if (not isUR(curr_affil)):

                        affil_hist = auth_id_query(auth_data[2])

                        try:
                            if (len(affil_hist) > 1):
                                for institution in affil_hist:
                                    try:
                                        affil_instance = institution['ip-doc']['preferred-name']['$']
                                        # if UR affil is found, return immediately
                                        if (isUR(affil_instance)):
                                            curr_affil = affil_instance
                                            auth_data[3] = curr_affil
                                            return auth_data
                                    except:
                                        print("Affiliation instance data for %s,%s wasn't structured correctly." % (auth_data[0], auth_data[1]))
                                        # print(institution)
                            else:
                                try:
                                    affil_instance = affil_hist['ip-doc']['preferred-name']['$']
                                    try:
                                        # if UR affil is found, return immediately
                                        if (isUR(affil_instance)):
                                            curr_affil = affil_instance
                                            auth_data[3] = curr_affil
                                            return auth_data
                                    except TypeError:
                                        print("isUR error")
                                        print(affil_instance)
                                except:
                                    print("Affiliation instance data for %s,%s wasn't structured correctly." % (auth_data[0], auth_data[1]))
                                    # print(institution)

                        except TypeError:
                            print("Type Error occured for affil_hist of %s,%s" % (auth_data[0], auth_data[1]))
                            print(affil_hist)

                    # but if it is then return immediately
                    else:
                        print("Returned with curr_affil : '%s' for %s,%s" % (curr_affil, auth_data[0], auth_data[1]))
                        auth_data[3] = curr_affil
                        return auth_data

                except:
                    print("Something wrong within the returned profile data of %s,%s" % (auth_data[0], auth_data[1]))

            # this is the case of hitting the cap of 25, too many people down the list
            if (len(auth_srch.results) >= 25):
                print("Results CAP of 25 was hit for the %d results of %s,%s" % (len(auth_srch.results), auth_data[0], auth_data[1]))
                auth_data[3] = 'max'
                return auth_data

            # this covers the case of no UR affils found at all
            elif (len(auth_srch.results) < 25):
                print("EXHAUSTED results list of %d results for %s,%s" % (len(auth_srch.results), auth_data[0], auth_data[1]))
                auth_data[3] = 'na'
                return auth_data

        # this could be a false positive! the author name could be in the name-variant field
        # I redo the query down below in the next function
        else:
            auth_data[2] = 'DNE'
            auth_data[3] = 'DNE'
            print(error_message)

    else:
        print("very bad error @ length of auth_srch.results <= 0")
        auth_data[2] = 'NONE'
        auth_data[3] = 'NONE'

    return auth_data
Exemple #7
0
    def auth_query(auth_last, auth_first):

        auth_data = [auth_last, auth_first]
        print("Searching for author %s, %s" % (auth_last, auth_first))
        # Initialize search object and execute search under the author index
        query = 'authlast(%s)+AND+authfirst(%s)' % (auth_last, auth_first)

        try:
            auth_srch = ElsSearch(query, 'author')
            auth_srch.execute(client, get_all=False)

        except:
            # Load other configuration with new API Key
            con_file = open("config2.json")
            config = json.load(con_file)
            con_file.close()

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

            auth_srch = ElsSearch(query, 'author')
            auth_srch.execute(client, get_all=False)

        if (len(auth_srch.results) == 1):
            print("auth_srch has", len(auth_srch.results), "result.")
        else:
            print("auth_srch has", len(auth_srch.results), "results.")

        # checking if no results at all
        error_message = auth_srch.results[0].get('error')

        if (len(auth_srch.results) > 0):

            if (not error_message):
                # grabs the author_id from the search data
                # this assumes that the wanted author is the first one in results
                # check this out later
                try:
                    string_author_id = auth_srch.results[0].get('dc:identifier')
                    # this line cuts the author id string from the end of AUTHOR_ID
                    # to the end of the id digits
                    author_id = string_author_id[10:]
                    print("author_id : %s" % author_id)
                    auth_data.append(author_id)
                except AttributeError:
                    print("Could not extract auth_id field for %s, %s" % (auth_last, auth_first))
                    auth_data.append("CNE")

                # grabs the curr_affil from the search data
                # appends it to auth_data
                try:
                    dict_curr_affil = auth_srch.results[0].get('affiliation-current')
                    curr_affil = dict_curr_affil.get('affiliation-name')
                    print("curr_affil : %s" % curr_affil)
                    auth_data.append(curr_affil)
                except AttributeError:
                    print("Could not extract curr_affil field for %s, %s" % (auth_last, auth_first))
                    auth_data.append("CNE")

            # this could be a false positive! the author name could be in the name-variant field
            # I redo the query down below in the next function
            else:
                auth_data.append("DNE")
                auth_data.append("DNE")
                print(error_message)

        else:
            print("very bad error @ length of auth_srch.results <= 0")
            auth_data.append("none")
            auth_data.append("none")

        return auth_data
Exemple #8
0
    'ce': 'http://www.elsevier.com/xml/ani/common',
    'prism': 'http://prismstandard.org/namespaces/basic/2.0/',
    'xsi': "http://www.w3.org/2001/XMLSchema-instance",
    'dc': 'http://purl.org/dc/elements/1.1/',
    'dcterms': 'http://purl.org/dc/terms/',
    'atom': 'http://www.w3.org/2005/Atom',
    'opensearch': 'http://a9.com/-/spec/opensearch/1.1/',
    'ani': 'http://www.elsevier.com/xml/ani/common'
}

config = json.load(open('matstract/config/db_creds.json', 'r'))["scopus"]
APIKEY = config["apikey"]

## Initialize client
CLIENT = ElsClient(config['apikey'], num_res=100)
CLIENT.inst_token = config['insttoken']


def check_scopus_collection(year, issn):
    """
    Checks the scopus_log collection on MongoDB whether the data for a given year/journal combination
    has been collected.

    Args:
        year: (str) year
        issn: (str) issn of journal

    Returns:
        (bool) True if status of the year/journal pair is "complete"

    """
Exemple #9
0
def elsevier_auth():
    ## Initialize client
    client = ElsClient("7a286322cb3559da3442a03892947ae4")
    client.inst_token = ""
    return client
Exemple #10
0
def elsevier_auth():
    client = ElsClient("1ebaeb2ea719e96071ce074a5c341963")
    client.inst_token = "6383ea4db27ea6b7353107935f098932"
    return client