diff --git a/grc_price_utils.py b/grc_price_utils.py index 057ffe5..0c48628 100644 --- a/grc_price_utils.py +++ b/grc_price_utils.py @@ -21,8 +21,59 @@ GRC_PRICE_URLS = ("https://www.bybit.com/en/coin-price/gridcoin-research/", "https://coinstats.app/coins/gridcoin/", "https://marketcapof.com/crypto/gridcoin-research/") +def parse_grc_price_soup(url: str, price_soup: str) -> tuple[Union[float, None], str, str]: + float_price = None + info_message = "" + url_message = "" -def get_grc_price_from_site() -> tuple[Union[float, None], str, list, list, list]: + soup = BeautifulSoup(price_soup, "html.parser") + + if url == "https://www.bybit.com/en/coin-price/gridcoin-research/": + pre_price = soup.find("div", attrs={"data-cy": "coinPrice"}) + + if pre_price is not None: + try: + price = pre_price.text.replace("$", "").strip() + float_price = float(price) + info_message = f"Found GRC price of {float_price} from {url}" + except Exception: + url_message = f"Error getting info from {url}" + else: + url_message = f"Error getting info from {url}" + elif url == "https://coinstats.app/coins/gridcoin/": + pre_price = soup.find("div", class_="CoinOverview_mainPrice__YygaC") + + if pre_price is not None: + try: + price = pre_price.p.text.replace("$", "").strip() + float_price = float(price) + info_message = f"Found GRC price of {float_price} from {url}" + except Exception: + url_message = f"Error getting info from {url}" + else: + url_message = f"Error getting info from {url}" + elif url == "https://marketcapof.com/crypto/gridcoin-research/": + pre_pre_price = soup.find("div", class_="price") + + if pre_pre_price is not None: + pre_price = pre_pre_price.find(string=True, recursive=False) + + if pre_price is not None: + try: + price = pre_price.replace("$", "").strip() + float_price = float(price) + info_message = f"Found GRC price of {float_price} from {url}" + except Exception: + url_message = f"Error getting info from {url}" + else: + url_message = f"Error getting info from {url}" + else: + url_message = f"Error getting info from {url}" + + return float_price, url_message, info_message + + +def get_grc_price_from_sites() -> tuple[Union[float, None], str, list, list, list]: headers = requests.utils.default_headers() headers["User-Agent"] = random.choice(AGENTS) found_prices = [] @@ -37,52 +88,13 @@ def get_grc_price_from_site() -> tuple[Union[float, None], str, list, list, list error_logger_messages.append(f"Error fetching stats from {url}: {error}") continue - soup = BeautifulSoup(response.content, "html.parser") + price, url_message, info_message = parse_grc_price_soup(url, response.content) - if url == "https://www.bybit.com/en/coin-price/gridcoin-research/": - pre_price = soup.find("div", attrs={"data-cy": "coinPrice"}) + if price is not None: + found_prices.append(price) - if pre_price is not None: - try: - price = pre_price.text.replace("$", "").strip() - float_price = float(price) - found_prices.append(float_price) - info_logger_messages.append(f"Found GRC price of {float_price} from {url}") - except Exception: - url_messages.append(f"Error getting info from {url}") - else: - url_messages.append(f"Error getting info from {url}") - elif url == "https://coinstats.app/coins/gridcoin/": - pre_price = soup.find("div", class_="CoinOverview_mainPrice__YygaC") - - if pre_price is not None: - try: - price = pre_price.p.text.replace("$", "").strip() - float_price = float(price) - found_prices.append(float_price) - info_logger_messages.append(f"Found GRC price of {float_price} from {url}") - except Exception: - url_messages.append(f"Error getting info from {url}") - else: - url_messages.append(f"Error getting info from {url}") - elif url == "https://marketcapof.com/crypto/gridcoin-research/": - pre_pre_price = soup.find("div", class_="price") - - if pre_pre_price is not None: - pre_price = pre_pre_price.find(string=True, recursive=False) - - if pre_price is not None: - try: - price = pre_price.replace("$", "").strip() - float_price = float(price) - found_prices.append(float_price) - info_logger_messages.append(f"Found GRC price of {float_price} from {url}") - except Exception: - url_messages.append(f"Error getting info from {url}") - else: - url_messages.append(f"Error getting info from {url}") - else: - url_messages.append(f"Error getting info from {url}") + url_messages.append(url_message) + info_logger_messages.append(info_message) if len(found_prices) > 0: table_message = f"Found GRC price {sum(found_prices) / len(found_prices)}" diff --git a/main.py b/main.py index 6ffd467..751e776 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,7 @@ from requests.auth import HTTPBasicAuth from typing import List, Union, Dict, Tuple, Set, Any import sys, signal - from grc_price_utils import get_grc_price_from_site + from grc_price_utils import get_grc_price_from_sites # This is needed for some async stuff import nest_asyncio @@ -968,7 +968,7 @@ def get_grc_price(sample_text: str = None) -> Union[float, None]: Raises: Exception: An error occurred accessing an online GRC price source. """ - price, table_message, url_messages, info_log_messages, error_log_messages = get_grc_price_from_site() + price, table_message, url_messages, info_log_messages, error_log_messages = get_grc_price_from_sites() for log_message in info_log_messages: log.info(log_message) diff --git a/pyproject.toml b/pyproject.toml index 1eaaf7d..8d17cf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ urllib3 = "^2.2.3" xmltodict = "^0.14.2" zope-interface = "^7.2" nest-asyncio = "^1.6.0" +beautifulsoup4 = "^4.13.3" [build-system] diff --git a/tests/main_tests.py b/tests/main_tests.py index 1569822..bd93b0f 100644 --- a/tests/main_tests.py +++ b/tests/main_tests.py @@ -1,12 +1,15 @@ -import sys import os +import sys sys.path.append(os.getcwd() + '/..') import json -import pytest, main, datetime -from typing import Dict, List, Union, Any, Tuple +from soups import SOUP_DICTIONARY +from grc_price_utils import parse_grc_price_soup + +import main, datetime +from typing import Dict, List def test_check_sidestake_original(): @@ -191,13 +194,18 @@ def test_update_fetch(): main.DATABASE["LASTUPDATECHECK"] = actual_update_check -def test_get_grc_price(): - sample_text = """CMC }

Gridcoin USD (GRC-USD)

CCC - CoinMarketCap. Currency in USD
0.010001-0.000136 (-1.34%)
As of 01:17AM UTC. Market open.
-COINGECKO $0.010917170129 """ - price = main.get_grc_price(sample_text) - print("price is {}".format(price)) - assert price == 0.010208382975086675 +def test_parse_grc_price_from_soup(): + for url, soup in SOUP_DICTIONARY.items(): + price, _, _ = parse_grc_price_soup(url, soup) + + assert price + + if url == "https://www.bybit.com/en/coin-price/gridcoin-research/": + assert price == 0.00384161 + elif url == "https://coinstats.app/coins/gridcoin/": + assert price == 0.003835 + elif url == "https://marketcapof.com/crypto/gridcoin-research/": + assert price == 0.00383864 def test_get_approved_project_urls_web(): diff --git a/tests/network/network_tests.py b/tests/network/network_tests.py index 82dc820..0ae3c76 100644 --- a/tests/network/network_tests.py +++ b/tests/network/network_tests.py @@ -1,8 +1,10 @@ import pytest import main +import grc_price_utils from typing import Dict,List,Tuple,Union,Any # Tests that require a network connection and will fail without one APPROVED_PROJECT_URLS={} + @pytest.fixture() def test_get_approved_project_urls_web(): """ @@ -11,31 +13,22 @@ def test_get_approved_project_urls_web(): """ global APPROVED_PROJECT_URLS APPROVED_PROJECT_URLS=main.get_approved_project_urls_web() + + def test_get_project_mag_ratios_from_url(test_get_approved_project_urls_web): result=main.get_project_mag_ratios_from_url(30,APPROVED_PROJECT_URLS) assert len(result)>3 -def test_get_grc_price_regex(): - # Function to test the regexes for getting grc price. Note this may fail if you get a "are you a bot?" page. - # Inspect HTML before assuming the regex is broken - import requests as req - import re - headers = req.utils.default_headers() - headers.update({ - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36', - }) - - sample_text=None - for url, info in main.PRICE_URL_DICT.items(): - regex = info[1] - name = info[0] - resp = '' - if sample_text: - resp = sample_text - else: - resp = req.get(url, headers=headers).text - regex_result = re.search(regex, resp) - assert regex_result - float(regex_result.group(2)) + + +def test_get_grc_price(): + # Function to test the soup finds for getting the grc price. Note this may fail if you get a "are you a bot?" page. + # Inspect the html before assuming that the finds are broken. + price, _, _, _, _ = grc_price_utils.get_grc_price_from_sites() + + assert price + assert isinstance(price,float) + + def test_grc_grc_price(): answer=main.get_grc_price() assert isinstance(answer,float) \ No newline at end of file diff --git a/tests/soups.py b/tests/soups.py new file mode 100644 index 0000000..398fef0 --- /dev/null +++ b/tests/soups.py @@ -0,0 +1,17 @@ +bybit_soup = """ +Gridcoin Price: GRC Live Price Today | Market Cap & Chart Analysis | Bybit
Gridcoin

Gridcoin Price

grc

$0.00384161
bybit downs
-21.05%
24H
7D
14D
30D
60D
200D
1Y
Low
$--
High
$--
loading...

Market Statistics\r\n

Market Cap
1.85M
24H Volume
--
Circulating Supply
481.09M
Max Supply
--

GRC Live Price Summary

As of Feb 8, 2025, the global cryptocurrency market cap is $1.85M with a -21.04% change in the last 24 hours. Today\'s price of GRC is $0.00384161, with a 24-hour trading volume of $--. GRC is -21.05% in the last 24 hours, with a circulating supply of 481.09M GRC coins and a maximum supply of -- GRC coins. GRC ranks 2980 by market cap. It has a 24H high of $0.00500415 recorded on Feb 8, 2025, and its 24H low so far is $0.00383436, recorded on Feb 8, 2025.

What Is the Highest Price of GRC?

GRC has an all-time high (ATH) of $0.214228 , recorded on Jan 9, 2018.

What Is the Lowest Price of GRC?

GRC has an all-time low (ATL) of $0.00060646, recorded on Jun 4, 2015.

How do you feel about Gridcoin today?
Vote to see what the community thinks
Bullish
Bearish
Follow Us on Social Media
+""" + +coinstats_soup = """ +Gridcoin Token Price, Charts & Market Insights | Your Crypto Hub
Deutsch\xed\x95\x9c\xea\xb5\xad\xec\x96\xb4\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e\xe4\xb8\xad\xe6\x96\x87Espa\xc3\xb1olFran\xc3\xa7ais\xd5\x80\xd5\xa1\xd5\xb5\xd5\xa5\xd6\x80\xd5\xa5\xd5\xb6Nederlands\xd0\xa0\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8\xd0\xb9ItalianoPortugu\xc3\xaasT\xc3\xbcrk\xc3\xa7ePortfolio TrackerSwapCryptocurrenciesPricingIntegrationsNewsEarnBlogNFTWidgetsDeFi Portfolio Tracker24h ReportPress KitAPI Docs
Rank #2882

Gridcoin Price

\xe2\x80\xa2GRC

$0.003835

21.51%

\xe0\xb8\xbf0.00000004

Gridcoin Price Chart (GRC)

Price
TradingView
1h24h1w1m3m6m1yAll
Swap
loading
$0
$0

Save on CoinStats Fees

Enjoy 0% Fees with Premium

Go Premium

Market Stats

Market Cap
$2M
Fully Diluted Valuation
$2M
Circulating Supply
481,094,990
Total Supply
497,428,030
Volume 24h
$19
Price Change (1h)
0.17%
Price Change (24h)
21.51%
Price Change (7d)
17.5%
All Time High

Jan 9, 2018

$0.21
98.21%
All Time Low

Jun 4, 2015

$0
532.96%
Gridcoin Price Update

Gridcoin price is $0.003835, down -21.51% in the last 24 hours, and the live market cap is $1,846,751. It has circulating supply of 481,094,990 GRC coins and a max supply of 497,428,030 GRC alongside $19 24h trading volume. Now, you can view this coin price in INR.

Notes

Crypto Converter

GRC

GRC

Holdings

About Gridcoin

What is Gridcoin?

\n

Gridcoin is an open source cryptocurrency (similar to Bitcoin) that rewards users for contributing to scientific research. It does this by rewarding users with coins for participating in BOINC (Berkeley Open Infrastructure for Network Computing) projects, which are used by researchers all over the world to study a variety of topics such as disease research, climate modeling, and astrophysics. The Gridcoin network also provides secure and efficient transactions between peers.

\n\n

Gridcoin was launched in 2013 and has since grown into one of the most successful cryptocurrencies in existence. It is based on a proof-of-stake system, meaning that users can earn coins simply by holding them in their wallets. This makes it easier for new users to get involved without having to mine or purchase large amounts of coins.

\n\n

The Gridcoin network is powered by its own blockchain, which allows it to process transactions quickly and securely. Transactions are verified by a distributed network of computers, ensuring that no single user can manipulate the system. This makes it ideal for use in applications such as online payments and trading.

\n\n

Gridcoin also offers a range of features designed to make it easy for developers to create applications on top of its blockchain. These include smart contracts, decentralized autonomous organizations (DAOs), and more. With these tools, developers can create innovative applications that could revolutionize how we interact with each other online.

\n\n

Gridcoin has become popular among scientists due to its ability to reward users who contribute computing power towards scientific research projects. By doing so, it helps support important research while providing an incentive for people to participate in the network.

\n\n

Overall, Gridcoin is an innovative cryptocurrency that combines the best aspects of both traditional currencies and blockchain technology. Its unique approach makes it an attractive option for those looking for a secure way to store value or transact online.

Read More

Categories

Related Assets
Trending Cryptocurrencies

Assets with the largest change in unique page views on CoinStats in the last 24 hours.

Similar Market Cap

Among all the assets available on CoinStats, these have the most similar market capitalization to Gridcoin.

Gridcoin Markets

See More
#ExchangePairVolume (24H)Volume (%)PriceLast Updated
1
FreiExchangeFreiExchange

GRC/BTC

$22100%

$0.003835

Recently

2
SouthXchangeSouthXchange

GRC/USDT

N/AN/A

$0.004501

1y ago

3
SouthXchangeSouthXchange

GRC/BCH

N/AN/A

$0.009326

1y ago

4
SouthXchangeSouthXchange

GRC/BTC

N/AN/A

$0.005586

1y ago

5
SouthXchangeSouthXchange

GRC/LTC

N/AN/A

$0.005392

1y ago

6
CashierestCashierest

GRC/USDT

N/AN/A

$0.004501

1y ago

Also Check Gridcoin Price On

Attention IconDisclaimer

No part of the content we provide constitutes financial advice on coin prices, legal advice, or any other form of advice meant for you to rely on for any purpose. Any use or reliance on our content is solely at your own risk and discretion.

+""" + +marketcapof_soup = """ +\n\n\n \n Gridcoin (GRC) Price and Market Cap | MarketCapOf\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n
\n
\n
\n \n
\n \n
\n \n
\n \n
\n
\n \n
\n
\n
\n
\n
\n
\n Gridcoin\n
\n
\n

Gridcoin (GRC)

\n
\n $0.00383864
\n
-$0.00095133 (19.86%)
\n
\n
\n
#1577 Rank in crypto
\n
\n
\n
\n
-$0.00095133 (19.86%)
\n
Last Update a Minute Ago
\n
\n
\n
\n
\n
\n
\n
\n
\n Price Range 7 Days\n A range in which the cryptocurrency price fluctuated within 7d.\n
\n
\n
\n
\n
\n $0.00383864\n $0.00517276\n
\n
\n
\n
\n
\n
\n Market Cap Range 7 Days\n A range in which the cryptocurrency market cap fluctuated within 7d.\n
\n
\n
\n
\n
\n $1,845,595\n $2,486,866\n
\n
\n
\n
\n
\n
\n
GRC compared with Top 5 Most Popular crypto
\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Price of GRCAsset BMkt. of BResults
\n
\n Gridcoin\n $3,956.35\n
\n
\n
\n Bitcoin BTC\n
\n
$1.90T\n 1,030,663.92x\n
\n
\n Gridcoin\n $654.95\n
\n
\n
\n Ethereum ETH\n
\n
$314.90B\n 170,621.26x\n
\n
\n Gridcoin\n $288.91\n
\n
\n
\n XRP XRP\n
\n
$138.91B\n 75,263.52x\n
\n
\n Gridcoin\n $196.62\n
\n
\n
\n Solana SOL\n
\n
$94.53B\n 51,221.20x\n
\n
\n Gridcoin\n $176.59\n
\n
\n
\n BNB BNB\n
\n
$84.90B\n 46,004.08x\n
\n
\n
\n
\n
\n
\n
\n
Price of GRC with the market cap of B
\n A hypothetical comparison on what would be the price of A cryptocurrency if it would reach B\'s Market Cap\n
\n
\n
\n
\n
\n \n
\n \n
Gridcoin
\n
GRC
\n
$0.00383864
\n
\n \n
\n
\n
\n
\n \n
\n
\n
\n \n
\n
\n
\n
\n
\n
Market cap
\n Market Cap is defined as the number of cryptocurrencies in circulation, multiplied by its price.\n
$1,845,595
\n
\n
\n
F.D. Market Cap
\n The total value of a project based on its entire future supply, not only tradable coins.\n
\xe2\x88\x9e
\n
\n
\n
\n
\n
Circulating Supply
\n The amount of cryptocurrencies that it\xe2\x80\x99s available to be traded.\n
480,794,050
\n
\n
\n
Total Supply
\n The total amount of coins of a specific crypto that were created/minted, that are in circulation, including those that are staked, locked, or reserved.\n
0
\n
\n
\n
\n
\n
\n
Gridcoin Price Chart (GRC-USD)
\n
\n
\n
Last Update a Minute Ago
\n
\n
\n \n \n
\n
\n \n
\n
\n
\n
\n\n\n\n\n\n\n\n\n \n\n\n\n +""" + +SOUP_DICTIONARY = { + "https://www.bybit.com/en/coin-price/gridcoin-research/": bybit_soup, + "https://coinstats.app/coins/gridcoin/": coinstats_soup, + "https://marketcapof.com/crypto/gridcoin-research/": marketcapof_soup +}