Skip to content

Instantly share code, notes, and snippets.

@btc100k
Created March 4, 2024 05:17
Show Gist options
  • Save btc100k/a715e4dcc6174bd965ad63f02c0ad504 to your computer and use it in GitHub Desktop.
Save btc100k/a715e4dcc6174bd965ad63f02c0ad504 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import sys
# This python script scrapes Ocean.xyz and creates a csv of the payouts to a given BTC address.
#
# it parses out:
# - 24h hash rate average
# - accepted 24h shares
# - stimated earnings/day
# - shares in reward window
#
# Is there value here for you?
# Value 4 Value: [email protected]
#
def output_for_address(ocean_addr: str):
url = f"https://ocean.xyz/stats/{ocean_addr}"
# Fetch the webpage
response = requests.get(url)
html = response.text
# Use Beautiful Soup to parse the HTML
soup = BeautifulSoup(html, 'html.parser')
# Find the table body
table_body = soup.find('tbody', id='hashrates-tablerows')
# Initialize variables to hold your data
hashrate_average = ''
accepted_shares = ''
# Iterate through each row in the table body
for row in table_body.find_all('tr', class_='table-row'):
# Check if the first cell contains '24 hrs'
if row.find('td', class_='table-cell').text.strip() == '24 hrs':
# Extract the hashrate average and accepted shares
cells = row.find_all('td', class_='table-cell')
hashrate_average = cells[1].text.strip()
accepted_shares = cells[2].text.strip()
break # Exit the loop since we found the desired row
print(f"Hashrate Average: {hashrate_average}")
print(f"Accepted Shares: {accepted_shares}")
def find_value_by_label(label, input_html):
my_soup = BeautifulSoup(input_html, 'html.parser')
containers = my_soup.find_all('div', class_='blocks-label')
for one in containers:
if label in one.text or one.text.startswith(label):
span = one.find_next_sibling('span')
if span:
return span.text.strip()
return None
earnings_day_value = find_value_by_label('Estimated Earnings/Day', html)
shares_reward_value = find_value_by_label('Shares In Reward Window', html)
if earnings_day_value:
print(f"Estimated Earnings/Day: {earnings_day_value}") # This will print: 0.01807883 BTC
else:
print("Estimated Earnings/Day not found")
if shares_reward_value:
print(f"Shares In Reward Window: {shares_reward_value}") # This will print: 5.86T
else:
print("Shares In Reward Window not found")
if __name__ == "__main__":
old_first = True
pages = 10
if len(sys.argv) > 1:
btc_address = sys.argv[1]
else:
btc_address = input("Please enter the address you're using to mine on Ocean.xyz: ")
#
# I'm not really documenting it, but you can pass in the # of pages to fetch in the 2nd argument
#
if len(sys.argv) > 2:
pages = int(sys.argv[2])
#
# I'm not really documenting it, but you can pass "false" as arg #3 if you want it sorted newest-to-oldest"
#
if len(sys.argv) > 3:
old_first = False if sys.argv[3].lower() == "false" else True
if len(btc_address):
print("")
output_for_address(ocean_addr=btc_address)
print("")
else:
print("\nNext time, enter a BTC address on the command line, or at the prompt. \nHappy Hashing!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment