From d66e9d96db00e8382c4d857e68cdc2e859c34c6a Mon Sep 17 00:00:00 2001 From: Jamie Walters Date: Mon, 16 Dec 2013 21:14:53 +0000 Subject: initial commit of program --- hashCheck.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 hashCheck.py (limited to 'hashCheck.py') diff --git a/hashCheck.py b/hashCheck.py new file mode 100644 index 0000000..34618f7 --- /dev/null +++ b/hashCheck.py @@ -0,0 +1,59 @@ +# hashCheck.py +# A basic JSON parser written to access the lite.coin-pool API +# by Jamie Walters (jagw@jagw.co.uk) + +import json +import urllib2 +from optparse import OptionParser + +# Our API key +api_key = "825abd217d7f72ed8a42f1bac0c56464d91dd7a480d99f99883f12474770c1ea" + +# The URL of the API we are calling. +url = "http://lite.coin-pool.com/api.php?api_key=" + api_key + +# Set up the command line arguments +parser = OptionParser(version="litecoinPool 1.0") +parser.add_option("-r", "--rewards", action="store_true", dest="rewards", + help="Print confirmed rewards") +parser.add_option("-p", "--payouthistory", action="store_true", dest="payouthistory", + help="Print payout history") +parser.add_option("-e", "--roundestimate", action="store_true", dest="roundestimate", + help="Print round estimated shares") +parser.add_option("-o", "--roundshares", action="store_true", dest="roundshares", + help="Print round shares") +parser.add_option("-t", "--hashrate", action="store_true", dest="hashrate", + help="Print hashrate of the miner") +parser.add_option("-u", "--username", action="store_true", dest="username", + help="Print Username of the miner") +parser.add_option("-j", "--json", action="store_true", dest="json", + help="Print raw JSON from the API - doesn't work fully") +(options, args) = parser.parse_args() + +# Make a call to the API using the URL we constructed earlier - throws error if there's a timeout etc. +try: + api_call= urllib2.urlopen(url) +except urllib2.URLError, e: + handleError(e) + +# Use the JSON library to decode the API call into something we can fiddle with +decoded_json = json.loads(api_call.read()) + +# For debug purposes, prints all the JSON out in human readable format +#print json.dumps(decoded_json, sort_keys=True, indent=4) + +# If the options are set, do these actions +if options.rewards: + print "Current rewards:", decoded_json['confirmed_rewards'] +if options.payouthistory: + print "Payout History:", decoded_json['payout_history'] +if options.roundestimate: + print "Current Round Estimate", decoded_json['round_estimate'] +if options.roundshares: + print "Current Round Shares", decoded_json['round_shares'] +if options.hashrate: + print "Current Hashrate:", decoded_json['total_hashrate'], "KH/s" +if options.username: + print "We are:", decoded_json['username'] +if options.json: + print decoded_json \ No newline at end of file -- cgit v1.2.3