Exemplo n.º 1
0
def get_nft_of_the_day() -> pd.DataFrame:
    """Scrapes data about nft of the day. [Source: CoinGecko]

    Returns
    -------
    pandas.DataFrame
        metric, value
    """

    url = "https://www.coingecko.com/en/nft"
    try:
        scraped_data = scrape_gecko_data(url)
    except RetryError as e:
        print(e)
        return pd.DataFrame()
    row = scraped_data.find("div", class_="tw-px-4 tw-py-5 sm:tw-p-6")
    try:
        *author, description, _ = clean_row(row)
        if len(author) > 3:
            author, description = author[:3], author[3]
    except (ValueError, IndexError):
        return pd.DataFrame()
    df = (pd.Series({
        "author": " ".join(author),
        "desc": description,
        "url": GECKO_BASE_URL + row.find("a")["href"],
        "img": row.find("img")["src"],
    }).to_frame().reset_index())
    df.columns = ["Metric", "Value"]
    df["Metric"] = df["Metric"].apply(
        lambda x: replace_underscores_in_column_names(x)
        if isinstance(x, str) else x)
    df = wrap_text_in_df(df, w=100)
    return df
Exemplo n.º 2
0
def display_info(symbol: str, export: str) -> None:
    """Shows basic information about loaded coin. [Source: CoinGecko]

    Parameters
    ----------
    symbol : str
        Cryptocurrency
    export : str
        Export dataframe data to csv,json,xlsx file
    """

    coin = gecko.Coin(symbol)

    df = wrap_text_in_df(coin.get_base_info, w=80)

    print_rich_table(df,
                     headers=list(df.columns),
                     show_index=False,
                     title="Basic Coin Information")
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "info",
        df,
    )
Exemplo n.º 3
0
def display_info(coin: gecko.Coin, export: str) -> None:
    """Shows basic information about loaded coin. [Source: CoinGecko]

    Parameters
    ----------
    coin : gecko_coin.Coin
        Cryptocurrency
    export : str
        Export dataframe data to csv,json,xlsx file
    """

    df = wrap_text_in_df(coin.get_base_info, w=80)

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                df,
                headers=df.columns,
                floatfmt=".2f",
                showindex=False,
                tablefmt="fancy_grid",
            ),
            "\n",
        )
    else:
        print(df.to_string, "\n")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "info",
        df,
    )
Exemplo n.º 4
0
def get_yield_farms() -> pd.DataFrame:
    """Scrapes yield farms data from "https://www.coingecko.com/en/yield-farming"

    Returns
    -------
    pandas.DataFrame
        Rank, Name, Pool, Audits, Collateral, Value Locked, Return Year, Return Hour
    """
    columns = [
        "Rank",
        "Name",
        "Pool",
        "Audits",
        "Collateral",
        "Value_Locked",
        "Return_Year",
    ]
    url = "https://www.coingecko.com/en/yield-farming"
    rows = scrape_gecko_data(url).find("tbody").find_all("tr")
    results = []
    for row in rows:
        row_cleaned = clean_row(row)[:-2]
        if " New" in row_cleaned:  # find better way to fix it in future
            row_cleaned.remove(" New")

        if len(row_cleaned) == 7:
            row_cleaned.insert(2, None)
        (
            rank,
            name,
            pool,
            *others,
            _,
            value_locked,
            apy1,
            _,  # hourly removed for most cases it's 0.00 so it doesn't bring any value for user
        ) = row_cleaned
        auditors, collateral = collateral_auditors_parse(others)
        auditors = ", ".join(aud.strip() for aud in auditors)
        collateral = ", ".join(coll.strip() for coll in collateral)
        results.append(
            [
                rank,
                name,
                pool,
                auditors,
                collateral,
                value_locked,
                apy1,
            ]
        )
    df = pd.DataFrame(results, columns=columns).replace({"": None})
    for col in ["Return_Year"]:
        df[col] = df[col].apply(
            lambda x: x.replace(" Yearly", "") if isinstance(x, str) else x
        )
    df["Rank"] = df["Rank"].astype(int)
    df = wrap_text_in_df(df, w=30)
    return df
def info(coin: gecko.Coin, other_args: List[str]):
    """Shows basic information about loaded coin

    Parameters
    ----------
    coin : gecko_coin.Coin
        Cryptocurrency
    other_args : List[str]
        argparse arguments

    """
    parser = argparse.ArgumentParser(
        add_help=False,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        prog="info",
        description="""
         Shows basic information about loaded coin like:
         Name, Symbol, Description, Market Cap, Public Interest, Supply, and Price related metrics
         """,
    )

    try:
        ns_parser = parse_known_args_and_warn(parser, other_args)

        if not ns_parser:
            return

        df = wrap_text_in_df(coin.base_info, w=80)
        print(
            tabulate(
                df,
                headers=df.columns,
                floatfmt=".2f",
                showindex=False,
                tablefmt="fancy_grid",
            ),
            "\n",
        )

    except SystemExit:
        print("")
    except Exception as e:
        print(e, "\n")