<commit_before>import os
import netrc

from os.path import expanduser

from click import ClickException

OS_WIN = True if os.name == 'nt' else False
NETRC_FILE = expanduser('~/_netrc') if OS_WIN else expanduser('~/.netrc')


def find_api_key():
    """
    Raises:
        ClickException: if no credentials are found
    """
    key = os.getenv("SHUB_APIKEY")
    if not key:
        key = get_key_netrc()

    if not key:
        err = 'Not logged in. Please login first with: shub login'
        raise ClickException(err)

    return key


def get_key_netrc():
    """Gets the key from the netrc file"""
    try:
        info = netrc.netrc(NETRC_FILE)
    except IOError:
        return
    try:
        key, account, password = info.authenticators("scrapinghub.com")
    except TypeError:
        return
    if key:<commit_msg>Lower the $SHUB_APIKEY precedence<commit_after>import os
import netrc

from os.path import expanduser

from click import ClickException

OS_WIN = True if os.name == 'nt' else False
NETRC_FILE = expanduser('~/_netrc') if OS_WIN else expanduser('~/.netrc')


def find_api_key():
    """
    Raises:
        ClickException: if no credentials are found
    """
    key = get_key_netrc()

    if not key:
        key = os.getenv("SHUB_APIKEY")

    if not key:
        err = 'Not logged in. Please login first with: shub login'
        raise ClickException(err)

    return key


def get_key_netrc():
    """Gets the key from the netrc file"""
    try:
        info = netrc.netrc(NETRC_FILE)
    except IOError:
        return
    try:
        key, account, password = info.authenticators("scrapinghub.com")
    except TypeError:
        return
    if key:
{'fraction_non_alphanumeric': 0.09577632361689471, 'fraction_numerical': 0.0, 'mean_word_length': 2.664488017429194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5951809', 'n_tokens_mistral': 547, 'n_tokens_neox': 530, 'n_words': 168}