summaryrefslogtreecommitdiff
path: root/hashCheck.py
blob: 34618f77f5e65c7497a5f59b0649002a48ae8092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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