Files
OpenBB/gamestonk_terminal/cryptocurrency/defi/defipulse_model.py
Colin Delahunty 6994273aad Fraud error (#944)
* Updated try except

* Added patch for fraud

* Updated tests

* Fix

* Attempting to resolve test issue

* Fixed again

Co-authored-by: Colin Delahunty <colindelahunty@Colins-Air.indiana.edu>
2021-11-15 15:12:15 -05:00

51 lines
1.2 KiB
Python

"""DeFi Pulse model"""
__docformat__ = "numpy"
import requests
from bs4 import BeautifulSoup
import pandas as pd
from gamestonk_terminal.helper_funcs import try_except
@try_except
def get_defipulse_index() -> pd.DataFrame:
"""Scrapes data from DeFi Pulse with all DeFi Pulse crypto protocols.
[Source: https://defipulse.com/]
Returns
-------
pd.DataFrame
List of DeFi Pulse protocols.
"""
req = requests.get("https://defipulse.com/")
result = req.content.decode("utf8")
soup = BeautifulSoup(result, features="lxml")
table = soup.find("tbody").find_all("tr")
list_of_records = []
for row in table:
row_elements = []
for element in row.find_all("td"):
text = element.text
row_elements.append(text)
list_of_records.append(row_elements)
df = pd.DataFrame(
list_of_records,
columns=[
"x",
"Rank",
"Name",
"Chain",
"Category",
"TVL",
"Change_1D",
],
)
df["Rank"] = df["Rank"].apply(lambda x: int(x.replace(".", "")))
df.drop("x", axis=1, inplace=True)
return df