How to use the pybliometrics.scopus.utils.config.has_section function in pybliometrics

To help you get started, we’ve selected a few pybliometrics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pybliometrics-dev / pybliometrics / pybliometrics / scopus / utils / get_content.py View on Github external
'Accept': 'application/json',
        'User-Agent': user_agent
        }
    if config.has_option('Authentication', 'InstToken'):
        token = config.get('Authentication', 'InstToken')
        header.update({'X-ELS-APIKey': key, 'X-ELS-Insttoken': token})
    # Perform request
    params.update(**kwds)
    # If config.ini has a section as follows:
    #
    # [Proxy]
    # https = protocol://server:port
    #
    # it uses a proxy as defined
    # see requests documentation for details
    if config.has_section("Proxy"):
        proxyDict = dict(config.items("Proxy"))
        resp = requests.get(url, headers=header, proxies=proxyDict, params=params)
    else:
        resp = requests.get(url, headers=header, params=params)
    # Handle error messages
    if resp.ok:
        return resp
    else:
        # Try raising ScopusError with supplied error message
        # if no message given, do without supplied error message
        # at least raise requests error
        if resp.status_code in errors:
            try:
                reason = resp.json()['service-error']['status']['statusText']
            except:
                reason = ""
github pybliometrics-dev / pybliometrics / pybliometrics / scopus / utils / get_content.py View on Github external
def get_folder(api, view):
    """Auxiliary function to get the cache folder belonging to a an API
    and eventually create the folder.
    """
    if not config.has_section('Directories'):
        create_config()
    try:
        folder = config.get('Directories', api)
    except NoOptionError:
        folder = DEFAULT_PATHS[api]
    folder = os.path.join(folder, view or '')
    if not os.path.exists(folder):
        os.makedirs(folder)
    return folder