#!/usr/bin/env python3 # API description (such as it is): http://www.zpool.ca/site/api import pprint import json import sys import datetime import time import subprocess import os import socket import urllib.request import urllib.parse # load config cfg=json.loads(open(sys.argv[1]).read()) miners=json.loads(open(sys.argv[2]).read()) algo_map=json.loads(open(sys.argv[3]).read()) card_type=cfg["card_type"] currency=cfg["currency"] pwrcost=cfg["pwrcost"] min_profit=cfg["min_profit"] payment_currency=cfg["payment_currency"] payment_addr=cfg["payment_addr"] os.environ["DISPLAY"]=":0" # grab something from a website def fetch(url): r=urllib.request.Request(url, None, {"User-Agent": "Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1", "Pragma": "no-cache"}) return urllib.request.urlopen(r).read().decode("utf-8") # main try: exchrate=float(json.loads(fetch("https://api.coinbase.com/v2/exchange-rates?currency=BTC"))["data"]["rates"][currency]) data=json.loads(fetch("http://www.zpool.ca/api/status")) except: print("unable to retrieve remote data", file=sys.stderr) sys.exit(-1) # update algo map changed=False for i in data: try: k=algo_map[i] except: algo_map[i]="" changed=True if (changed==True): with open(sys.argv[3], "w") as outfile: json.dump(algo_map, outfile, sort_keys=True, indent=2) # weed out miners not supported by the pool filtered_miners={} for i in data: try: filtered_miners[algo_map[i]]=miners[algo_map[i]] except: pass miners=filtered_miners # adjust estimates so they're all in the same units: BTC/day per GH/s for i in data: data[i]["estimate_current"]=float(data[i]["estimate_current"])*1000 try: data["sha256"]["estimate_current"]/=1000000000 except: pass try: data["equihash"]["estimate_current"]*=1000 except: pass for i in ["scrypt", "blakecoin", "blake2s", "decred", "x11", "quark", "qubit", "keccak"]: try: data[i]["estimate_current"]/=1000 except: pass # calculate profitability for our hardware coins={} for i in data: if (algo_map[i]!=""): coins[i]=miners[algo_map[i]] coins[i]["bin"]=coins[i]["bin"].format(HOST=i+".mine.zpool.ca", PORT=data[i]["port"], USERNAME=payment_addr, PASSWORD="c="+payment_currency) coins[i]["algo"]=i coins[i]["mapped_algo"]=algo_map[i] coins[i]["name"]=i coins[i]["estimate"]=data[i]["estimate_current"]*float(coins[i]["speed"])-24.0*coins[i]["power"]*pwrcost/exchrate # sort by profitability sort={} for i in coins: sort[i]=coins[i]["estimate"] sort=sorted(sort.items(), key=lambda x:x[1], reverse=True) log=open("current-profit", "w") for i in sort: log.write(i[0]+": "+format(i[1], ".8f")+" BTC/day ("+format(i[1]*exchrate, ".2f")+" "+currency+"/day)\n") log.close() miner=coins[sort[0][0]] if (len(sys.argv)==4): # exit if maximum is below minimum if (miner["estimate"]