Exemple #1
0
def pip_version_check(session):
    """Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    """
    import pip  # imported here to prevent circular imports
    pypi_version = None

    try:
        state = load_selfcheck_statefile()

        current_time = datetime.datetime.utcnow()
        # Determine if we need to refresh the state
        if "last_check" in state.state and "pypi_version" in state.state:
            last_check = datetime.datetime.strptime(
                state.state["last_check"],
                SELFCHECK_DATE_FMT
            )
            if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
                pypi_version = state.state["pypi_version"]

        # Refresh the version if we need to or just see if we need to warn
        if pypi_version is None:
            resp = session.get(
                PyPI.pip_json_url,
                headers={"Accept": "application/json"},
            )
            resp.raise_for_status()
            pypi_version = [
                v for v in sorted(
                    list(resp.json()["releases"]),
                    key=packaging_version.parse,
                )
                if not packaging_version.parse(v).is_prerelease
            ][-1]

            # save that we've performed a check
            state.save(pypi_version, current_time)

        pip_version = packaging_version.parse(pip.__version__)
        remote_version = packaging_version.parse(pypi_version)

        # Determine if our pypi_version is older
        if (pip_version < remote_version and
                pip_version.base_version != remote_version.base_version):
            logger.warning(
                "You are using pip version %s, however version %s is "
                "available.\nYou should consider upgrading via the "
                "'pip install --upgrade pip' command." % (pip.__version__,
                                                          pypi_version)
            )

    except Exception:
        logger.debug(
            "There was an error checking the latest version of pip",
            exc_info=True,
        )
Exemple #2
0
def datetime2timestamp(dt, convert_to_utc=False):
    """ Converts a datetime object to UNIX timestamp in milliseconds. """
    if isinstance(dt, datetime.datetime):
        if convert_to_utc:  # 是否转化为UTC时间
            dt = dt + datetime.timedelta(hours=-8)  # 中国默认时区
        timestamp = total_seconds(dt - EPOCH)
        return long(timestamp)
    return dt
Exemple #3
0
def pip_version_check(session):
    """Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    """
    import pip  # imported here to prevent circular imports
    pypi_version = None

    try:
        state = load_selfcheck_statefile()

        current_time = datetime.datetime.utcnow()
        # Determine if we need to refresh the state
        if "last_check" in state.state and "pypi_version" in state.state:
            last_check = datetime.datetime.strptime(state.state["last_check"],
                                                    SELFCHECK_DATE_FMT)
            if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
                pypi_version = state.state["pypi_version"]

        # Refresh the version if we need to or just see if we need to warn
        if pypi_version is None:
            resp = session.get(
                PyPI.pip_json_url,
                headers={"Accept": "application/json"},
            )
            resp.raise_for_status()
            pypi_version = [
                v for v in sorted(
                    list(resp.json()["releases"]),
                    key=packaging_version.parse,
                ) if not packaging_version.parse(v).is_prerelease
            ][-1]

            # save that we've performed a check
            state.save(pypi_version, current_time)

        pip_version = packaging_version.parse(pip.__version__)
        remote_version = packaging_version.parse(pypi_version)

        # Determine if our pypi_version is older
        if (pip_version < remote_version
                and pip_version.base_version != remote_version.base_version):
            logger.warning(
                "You are using pip version %s, however version %s is "
                "available.\nYou should consider upgrading via the "
                "'pip install --upgrade pip' command." %
                (pip.__version__, pypi_version))

    except Exception:
        logger.debug(
            "There was an error checking the latest version of pip",
            exc_info=True,
        )
Exemple #4
0
def pip_version_check(package_finder):
    """Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    """
    installed_version = get_installed_version("pip")
    if installed_version is None:
        return

    pip_version = packaging_version.parse(installed_version)
    remote_version = None

    try:
        state = load_selfcheck_statefile()

        current_time = datetime.datetime.utcnow()
        # Determine if we need to refresh the state
        if "last_check" in state.state and "remote_version" in state.state:
            last_check = datetime.datetime.strptime(state.state["last_check"],
                                                    SELFCHECK_DATE_FMT)
            if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
                remote_version = state.state["remote_version"]

        # Refresh the version if we need to or just see if we need to warn
        if remote_version is None:
            try:
                remote_version = package_finder.find_requirement(
                    InstallRequirement.from_line('pip'), upgrade=True).version
            except BestVersionAlreadyInstalled:
                remote_version = pip_version

            remote_version = remote_version.base_version

            # save that we've performed a check
            state.save(remote_version, current_time)

        if not remote_version == installed_version:
            # Advise "python -m pip" on Windows to avoid issues
            # with overwriting pip.exe.
            if WINDOWS: pip_cmd = "python -m pip"
            else:
                pip_cmd = "pip"
            logger.warning(
                "You are using pip version %s, however version %s is "
                "available.\nYou should consider upgrading via the "
                "'%s install --upgrade pip' command.", pip_version,
                remote_version, pip_cmd)

    except Exception:
        logger.debug(
            "There was an error checking the latest version of pip",
            exc_info=True,
        )
    def cmd_pip_check_version(self, *argv, **kwargs):
        list_command = ListCommand()
        options, args = list_command.parse_args([])
        session = list_command._build_session(options, retries=0, timeout=min(5, options.timeout))

        installed_version = get_installed_version("pip")

        if installed_version is None:
            return

        pypi_version = None

        try:
            state = load_selfcheck_statefile()
            current_time = datetime.datetime.utcnow()
            if "last_check" in state.state and "pypi_version" in state.state:
                last_check = datetime.datetime.strptime(
                    state.state["last_check"],
                    SELFCHECK_DATE_FMT
                )
                if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
                    pypi_version = state.state["pypi_version"]

            # Refresh the version if we need to or just see if we need to warn
            if pypi_version is None:
                resp = session.get(
                    PyPI.pip_json_url,
                    headers={"Accept": "application/json"},
                )
                resp.raise_for_status()
                pypi_version = [
                    v for v in sorted(
                        list(resp.json()["releases"]),
                        key=parse_version,
                    )
                    if not parse_version(v).is_prerelease
                ][-1]

                state.save(pypi_version, current_time)
        except Exception:
            pass

        return 'pip', installed_version, str(pypi_version)
def collect_data(path, coins):
    interval = int(total_seconds(datetime.timedelta(days=14)) * 1000)
    start = datetime.datetime(year=2013, month=6, day=1, hour=0, minute=0)
    start = int(start.timestamp() * 1000)
    end = datetime.datetime.now()
    end = int(end.timestamp() * 1000)

    url = 'http://index.bithumb.com/api/coinmarketcap/localAPI.php'

    target = start
    print("Collecting coin data : ", coins)

    arr = []
    title = []  # title of columns
    title.append("time")

    for coin in coins:
        title.append(coin)

    arr.append(title)

    while (target <= end):
        json_list = []
        json_len = 0

        for coin in coins:

            if target + interval >= end:
                res = rq.get(url,
                             params={
                                 'api': 'graph',
                                 'coin': 'btc',
                                 'subject': 'price_usd',
                                 'start': target,
                                 'end': end
                             })
            else:
                res = rq.get(url,
                             params={
                                 'api': 'graph',
                                 'coin': 'btc',
                                 'subject': 'price_usd',
                                 'start': target,
                                 'end': target + interval
                             })

            if (coin == 'btc'):
                json_len = len(res.json())

            temp = []
            if len(res.json()) < json_len:  # add default values
                for i in range(json_len - len(res.json())):
                    temp.append([0, 0])

                temp = temp + res.json()
                json_list.append(temp)
            else:
                json_list.append(res.json())

        target = target + interval

        for i in range(json_len):
            row = []
            row.append(time.ctime(json_list[0][i][0] / 1000))  # add timestamp

            for j in range(len(json_list)):
                row.append(json_list[j][i][1])

            arr.append(row)

    np.savetxt(path, arr, delimiter=',', fmt="%s")
    print("Coin data saved in : ", path)
def pip_version_check(session):
    """Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    """
    installed_version = get_installed_version("pip")
    if installed_version is None:
        return

    pip_version = packaging_version.parse(installed_version)
    pypi_version = None

    try:
        state = load_selfcheck_statefile()

        current_time = datetime.datetime.utcnow()
        # Determine if we need to refresh the state
        if "last_check" in state.state and "pypi_version" in state.state:
            last_check = datetime.datetime.strptime(state.state["last_check"],
                                                    SELFCHECK_DATE_FMT)
            if total_seconds(current_time - last_check) < 7 * 24 * 60 * 60:
                pypi_version = state.state["pypi_version"]

        # Refresh the version if we need to or just see if we need to warn
        if pypi_version is None:
            resp = session.get
            resp.raise_for_status()
            pypi_version = [
                v for v in sorted(
                    list(resp.json()["releases"]),
                    key=packaging_version.parse,
                ) if not packaging_version.parse(v).is_prerelease
            ][-1]

            # save that we've performed a check
            state.save(pypi_version, current_time)

        remote_version = packaging_version.parse(pypi_version)

        # Determine if our pypi_version is older
        if (pip_version < remote_version
                and pip_version.base_version != remote_version.base_version):
            # Advise "python -m pip" on Windows to avoid issues
            # with overwriting pip.exe.
            if WINDOWS:
                pip_cmd = "python -m pip"
            else:
                pip_cmd = "pip"
            logger.warning(
                "You are using pip version %s, however version %s is "
                "available.\nYou should consider upgrading via the "
                "'%s install --upgrade pip' command.", pip_version,
                pypi_version, pip_cmd)

    except Exception:
        logger.debug(
            "There was an error checking the latest version of pip",
            exc_info=True,
        )