116 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			116 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env python3
 | |
| 
 | |
| # API description: http://www.zpool.ca/site/api
 | |
| # estimates: values in mBTC/MH/day, 
 | |
| #                      mBTC/PH/day for sha256
 | |
| #		       mBTC/GH/day for scrypt, blake, decred, x11, quark, qubit
 | |
| #		       mBTC/kS/day for equihash
 | |
| 
 | |
| import pprint
 | |
| import json
 | |
| import urllib.request
 | |
| import urllib.parse
 | |
| import sys
 | |
| import datetime
 | |
| import time
 | |
| import subprocess
 | |
| import os
 | |
| import socket
 | |
| 
 | |
| # load config
 | |
| 
 | |
| DEBUG=False
 | |
| 
 | |
| 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"]
 | |
| #user_name=cfg["user_name"]
 | |
| #miner_name=cfg["miner_name"]
 | |
| 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"
 | |
| 
 | |
| # IPv4 address lookup
 | |
| 
 | |
| def addr(host):
 | |
|   return [addr[4][0] for addr in socket.getaddrinfo(host, None) if addr[0] == socket.AF_INET][0]
 | |
| 
 | |
| # grab something from a website
 | |
| 
 | |
| def fetch(prot, host, path, forceipv4=False):
 | |
|   if (forceipv4):
 | |
|     url=prot+"://"+addr(host)+"/"+path
 | |
|   else:
 | |
|     url=prot+"://"+host+"/"+path
 | |
|   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", "Host": host})
 | |
|   return urllib.request.urlopen(r).read().decode("utf-8")
 | |
| 
 | |
| # main
 | |
| 
 | |
| if (DEBUG!=True):
 | |
|   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", True))
 | |
| else:
 | |
|   exchrate=float(json.loads(open("dbgdata-exchange-rates").read())["data"]["rates"][currency])
 | |
|   data=json.loads(open("dbgdata-status").read())
 | |
| 
 | |
| # 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)
 | |
| 
 | |
| # adjust estimates so they're all in the same units: BTC/day per GH/s 
 | |
| for i in data:
 | |
|   data[i]["adjusted_estimate"]=float(data[i]["estimate_current"])*1000
 | |
| try:
 | |
|   data["sha256"]["adjusted_estimate"]/=1000000000000
 | |
| except:
 | |
|   pass
 | |
| try:
 | |
|   data["equihash"]["adjusted_estimate"]*=1000
 | |
| except:
 | |
|   pass
 | |
| for i in ["scrypt", "blakecoin", "blake2s", "decred", "x11", "quark", "qubit", "keccak"]:
 | |
|   try:
 | |
|     data[i]["adjusted_estimate"]/=1000
 | |
|   except:
 | |
|     pass
 | |
|   
 | |
| 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]["adjusted_estimate"]*float(coins[i]["speed"]) # factor in our speed    
 | |
|     
 | |
| for i in data:
 | |
|   print(i+": "+str(data[i]["estimate_current"])+" "+str(data[i]["adjusted_estimate"]))
 | |
|   
 | |
| print("")
 | |
| 
 | |
| for i in coins:
 | |
|   print(i+": "+str(coins[i]["estimate"]))
 | |
| 
 | |
| print("")
 | |
| 
 | |
| for i in coins:
 | |
|   print(i+": "+str(coins[i]["bin"]))
 |