Last active
January 22, 2018 23:08
-
-
Save tpruvot/3e32d6837e49925d460b804cb79d08b2 to your computer and use it in GitHub Desktop.
Hexchat YiiMP api query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import hexchat | |
import json | |
__module_name__ = "YiiMP API query" | |
__module_version__ = "1.2" | |
__module_description__ = "Report pool rate when you type /yiimp or trigger !yiimp" | |
__author__ = "tpruvot" | |
__url_api__ = "http://yiimp.ccminer.org/api/" | |
full_name = "%s v%s by %s" % (__module_name__, __module_version__, __author__) | |
help_hook = "\"/yiimp <algo|currency>\" reports workers and hashrate in channel." | |
def yiimp_query(words, word_eol, userdata): | |
url = __url_api__ + "status" | |
algo = "decred" | |
if len(words) == 2: | |
algo = words[1] | |
request = urllib.request.Request(url) | |
try: | |
response = urllib.request.urlopen(request); | |
except IOError as e: | |
if hasattr(e, 'code'): | |
hexchat.prnt("An error occured, HTTP code %d was returned." % e.code) | |
return hexchat.EAT_ALL | |
try: | |
data = json.loads(response.read().decode()) | |
except JSONDecodeError as e: | |
hexchat.prnt("JSON error %s at %d " % (e.msg, e.lineno)) | |
return hexchat.EAT_ALL | |
found = 0 | |
for key, attrs in data.items(): | |
if key.find(algo) >= 0: | |
hashrate = attrs["hashrate"] | |
workers = attrs["workers"] | |
unit = "H/s" | |
if hashrate > 10000: | |
unit = "kH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "MH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "GH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "TH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "PH/s" | |
hashrate = hashrate / 1000 | |
if algo == "equihash": | |
unit = unit.replace("H/s","Sol/s") | |
hexchat.command("say YiiMP %s: %d miners %d %s" % (algo, workers, hashrate, unit)) | |
found = 1 | |
if not found: | |
url = __url_api__ + "currencies" | |
request = urllib.request.Request(url) | |
try: | |
response = urllib.request.urlopen(request); | |
except IOError as e: | |
if hasattr(e, 'code'): | |
hexchat.prnt("An error occured, HTTP code %d was returned." % e.code) | |
return hexchat.EAT_ALL | |
try: | |
data = json.loads(response.read().decode()) | |
except JSONDecodeError as e: | |
hexchat.prnt("JSON error %s at %d " % (e.msg, e.lineno)) | |
return hexchat.EAT_ALL | |
btc = 0.0 | |
blocks = 0 | |
for key, attrs in data.items(): | |
if key.find(algo) >= 0: | |
hashrate = attrs["hashrate"] | |
workers = attrs["workers"] | |
unit = "H/s" | |
if hashrate > 10000: | |
unit = "kH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "MH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "GH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "TH/s" | |
hashrate = hashrate / 1000 | |
if hashrate > 10000: | |
unit = "PH/s" | |
hashrate = hashrate / 1000 | |
if algo in ["ZEC","ZEN","KMD","HUSH","ZCL"]: | |
unit = unit.replace("H/s","Sol/s") | |
if "24h_btc" in attrs: | |
btc = float(attrs["24h_btc"]) | |
if "24h_blocks" in attrs: | |
blocks = float(attrs["24h_blocks"]) | |
hexchat.command("say YiiMP %s: %d miners %d %s, %.8f BTC (%d blocks)" % (algo, workers, hashrate, unit, btc, blocks)) | |
found = 1 | |
if not found: | |
hexchat.command("say %s does not exist" % (algo)) | |
return hexchat.EAT_ALL | |
def chan_trigger(params, word_eol, userdata): | |
if params[1].find('!yiimp') != -1: | |
yiimp_query(params[1].split(' '), word_eol, userdata) | |
hexchat.hook_command("yiimp", yiimp_query, help=help_hook) | |
hexchat.hook_print("Channel Message", chan_trigger) | |
# hexchat.hook_print("Private Message", chan_trigger) | |
hexchat.hook_print("Private Message to Dialog", chan_trigger) # test to myself | |
hexchat.prnt(full_name + " loaded.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment