Skip to content

Instantly share code, notes, and snippets.

@btc100k
Last active September 18, 2021 01:20
Show Gist options
  • Save btc100k/94a8567ba5e6d3e69e705e1c2d0aa4f7 to your computer and use it in GitHub Desktop.
Save btc100k/94a8567ba5e6d3e69e705e1c2d0aa4f7 to your computer and use it in GitHub Desktop.
Here is some python code that shows how you'd pull the S19's info and search for the LSTime. If the last share time is too large, you might want to restart the machine.
import requests
from requests.auth import HTTPDigestAuth
TEN_MINUTES_IN_SECONDS = 60 * 10
HIGH_LSTIME_IN_SECONDS = 120
session = requests.Session()
class S19Miner:
def __init__(self, ip_address):
self.ip_address = ip_addres
self.username = 'root'
self.password = 'root'
# This wraps around the http networking
def get(self, url):
try:
response = session.get(url=url, auth=self.get_auth(), timeout=(5, 10), allow_redirects=True, verify=False)
except requests.exceptions.RequestException as e: # This is the correct syntax
response = FakeResponse(599)
response.exception = e
return response
def get_auth(self):
return HTTPDigestAuth(self.username, self.password)
def update_last_share_time(self):
status_url = 'http://{ip}/cgi-bin/pools.cgi'.format(ip=self.ip_address)
response = self.get(status_url)
json_value = response.json()
pool_array = json_value['POOLS']
seconds_since_last = 24 * 60 * 60 # one day
if pool_array is not None:
for one_pool in pool_array:
pool_index = int(one_pool['index'])
if pool_index >= 0:
lstime = one_pool['lstime']
if lstime != "0":
last = timestamp_to_seconds(lstime)
if last < seconds_since_last:
seconds_since_last = last
if seconds_since_last < TEN_MINUTES_IN_SECONDS:
# we haven't submitted a share in 10 minutes.
# maybe we should bounce this worker
# print("Last share time valid: ", seconds_since_last)
pass
else:
print(self.ip_address, "Last share time too old: ", seconds_since_last)
# In my larger application, this line is relevant, but commenting for the gist
# self.status_string = LAST_SHARE_STRING
# In my larger application, this line is relevant, but commenting for the gist
# self.worker_stats.lstime = seconds_since_last
@btc100k
Copy link
Author

btc100k commented Sep 18, 2021

This probably will not work for your out of the box, but it shows:

  1. How to make an http call to your miner, with auth
  2. How to parse the response into a python dictionary that you can interrogate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment