Last active
August 29, 2015 14:04
-
-
Save cr5315/8e3c6e729d6cbdf47568 to your computer and use it in GitHub Desktop.
hardc0re left for a few days. So I made these.
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
from util.hook import * | |
import urllib2 | |
import json | |
# Global Shizz | |
hdr = {'User-Agent': 'Mozilla/5.0'} | |
################################################################################ | |
@hook(cmds=["addressbalance", "abalance", "bal"], rate=15, args=True) | |
def getbalance(code, input): | |
"""balance - fetches Dogecoin wallet address balance from Dogechain""" | |
args = input.group().split() | |
address = args[1] | |
# Validate the address | |
if len(address) is 34: | |
# Correct length, now check against Dogechain | |
queryURL = "http://dogechain.info/chain/Dogecoin/q/checkaddress/" + address | |
response = urllib2.urlopen(queryURL) | |
result = response.read() | |
response.close() | |
badresults = ["X5", "SZ", "CK"] | |
if result in badresults: | |
code.write(["NOTICE", input.nick, ":\x01", "Invalid Dogecoin address", "\x01"]) | |
else: | |
# Valid address, we're good to go | |
queryURL = "http://dogechain.info/chain/Dogecoin/q/addressbalance/" + address | |
response = urllib2.urlopen(queryURL) | |
result = response.read() | |
response.close() | |
code.write(["NOTICE", input.nick, ":\x01", result, "\x01"]) | |
else: | |
# Length wasn't 34 | |
code.write(["NOTICE", input.nick, ":\x01", "Invalid Dogecoin address", "\x01"]) |
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
from util.hook import * | |
import urllib2 | |
import json | |
from datetime import datetime, timedelta | |
# Global Shizz | |
hdr = {'User-Agent': 'Mozilla/5.0'} | |
################################################################################ | |
@hook(cmds=["halving", "halvening"], rate=15) | |
def halving(code, input): | |
halvings = [ 100000, 200000, 300000, 400000, 500000, 600000 ] | |
site = "http://dogechain.info/chain/Dogecoin/q/getblockcount" | |
req = urllib2.Request(site, headers=hdr) | |
response = urllib2.urlopen(req) | |
blockCount = int(response.read()) | |
response.close() | |
# Since the first two halvings are past, we're going to ignore them | |
if blockCount % 100000 == 0: | |
blocksRemaining = 0 | |
elif blockCount > halvings[1] and blockCount < halvings[2]: | |
blocksRemaining = halvings[2] - blockCount | |
elif blockCount > halvings[2] and blockCount < halvings[3]: | |
blocksRemaining = halvings[3] - blockCount | |
elif blockCount > halvings[3] and blockCount < halvings[4]: | |
blocksRemaining = halvings[4] - blockCount | |
elif blockCount > halvings[4] and blockCount < halvings[5]: | |
blocksRemaining = halvings[5] - blockCount | |
elif blockCount > halvings[5]: | |
blocksRemaining = -1 | |
else: | |
code.say("Something went horribly wrong") | |
return | |
if blocksRemaining == 0: | |
code.say("Block %d is here! The halving is now!" % blockCount) | |
elif blocksRemaining == -1: | |
code.say("There are no more halvings") | |
else: | |
secondsUntilHalving = blocksRemaining * 60 | |
# http://stackoverflow.com/questions/4048651/python-function-to-convert-seconds-into-minutes-hours-and-days | |
sec = timedelta(seconds=secondsUntilHalving) | |
d = datetime(1, 1, 1) + sec | |
if d.day - 1 == 1: | |
days = "%d day" % (d.day - 1) | |
else: | |
days = "%d days" % (d.day - 1) | |
if d.hour == 1: | |
hours = "%d hour" % d.hour | |
else: | |
hours = "%d hours" % d.hour | |
if d.minute == 1: | |
minutes = "%d minute" % d.minute | |
else: | |
minutes = "%d minutes" % d.minute | |
code.say(days + ", " + hours + ", " + minutes + " until the next halving") | |
################################################################################ | |
@hook(cmds=["blockcount"], rate=15) | |
def blockcount(code, input): | |
site = "http://dogechain.info/chain/Dogecoin/q/getblockcount" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
response = urllib2.urlopen(req) | |
count = response.read() | |
response.close() | |
code.reply("Last solved block: %s" % count) | |
except: | |
code.reply("There was an error") | |
################################################################################ | |
@hook(cmds=["diff"], rate=15) | |
def difficulty(code, input): | |
"""difficulty - fetches the last solved block difficulty from Dogechain""" | |
site = "http://dogechain.info/chain/Dogecoin/q/getdifficulty" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
response = urllib2.urlopen(req) | |
diff = response.read() | |
response.close() | |
code.say("Last solved block difficulty: " + str(diff)) | |
except: | |
code.say("There was an error fetching difficulty") |
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
from util.hook import * | |
import urllib2 | |
import json | |
# Global Shizz | |
hdr = {'User-Agent': 'Mozilla/5.0'} | |
################################################################################ | |
@hook(cmds=["khash"], rate=15, args=True) | |
def khash(code, input): | |
"""khash - calculates how much doge/day a certain khash/s would make using the SoChain API""" | |
args = input.group(2).split()[0] # Should only be the khash/s, nothing else | |
try: | |
# This should check for both numeric and positive input | |
# If it's not numeric, the float cast will raise an exception | |
# If it's negative the conditional will raise an exception | |
if float(args) < 0.0: | |
raise Exception("Negative input") | |
except: | |
code.write(["NOTICE", input.nick, ":\x01", "Invalid input. Please provide a positive number.", "\x01"]) | |
return | |
site = "https://chain.so/api/v2/get_info/DOGE" | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
hashRate = js["data"]["hashrate"] | |
difficulty = js["data"]["mining_difficulty"] | |
blockcount = js["data"]["blocks"] | |
newCoinsPerDay = 24 * 60 * getreward(blockcount) | |
userHash = (float(args) * 1000) / float(hashRate) | |
coinsPerDay = userHash * newCoinsPerDay | |
prettyNetworkHash = float(hashRate) / 1000 / 1000 / 1000 | |
message = "Network hashrate: %d GH. %skh/s will mine around %d doge/day" % (prettyNetworkHash, args, coinsPerDay) | |
code.write(["NOTICE", input.nick, ":\x01", message, "\x01"]) | |
def getreward(blockCount): | |
"""Returns the block reward""" | |
halvings = [ 0, 100000, 200000, 300000, 400000, 500000, 600000 ] | |
# We're at block 297683, so the first two halvings don't matter | |
if blockCount > halvings[2] and blockCount <= halvings[3]: | |
# Between blocks 200,001 and 300,000 | |
return 125000 | |
elif blockCount > halvings[3] and blockCount <= halvings[4]: | |
# Between blocks 300,001 and 400,000 | |
return 62500 | |
elif blockCount > halvings[4] and blockCount <= halvings[5]: | |
# Between blocks 400,001 and 500,000 | |
return 31250 | |
elif blockCount > halvings[5]: | |
# Past block 500,001 | |
return 10000 | |
else: | |
return -1 |
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
from util.hook import * | |
import urllib2 | |
import json | |
# Global Shizz | |
hdr = {'User-Agent': 'Mozilla/5.0'} | |
################################################################################ | |
@hook(cmds=["market", "dogecoin", "doge"], rate=30) | |
def market(code, input): | |
"""market - fetches Dogecoin price from several exchanges""" | |
# Exchanges: Cryptsy, Bter, MintPal, Vircurex, Doge -> USD from somewhere | |
# Cryptsy | |
site = "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=132" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
cryptsyValue = js["return"]["markets"]["DOGE"]["lasttradeprice"] | |
except: | |
cryptsyValue = "error" | |
# End Cryptsy | |
# Bter | |
site = "http://data.bter.com/api/1/ticker/doge_btc" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
bterValue = js["last"] | |
except: | |
bterValue = "error" | |
# End Bter | |
# MintPal | |
site = "https://api.mintpal.com/v1/market/stats/DOGE/BTC" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
mintpalValue = js[0]["last_price"] | |
except: | |
mintpalValue = "error" | |
# End MintPal | |
# Vircurex | |
site = "https://api.vircurex.com/api/get_last_trade.json?base=DOGE&alt=BTC" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
vircurexValue = js["value"] | |
except: | |
vircurexValue = "error" | |
# End Vircurex | |
# Cryptsy USD | |
site = "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=182" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
cryptsyusdValue = "1 DOGE = $" + str(js["return"]["markets"]["DOGE"]["lasttradeprice"]) | |
except: | |
cryptsyusdValue = "" | |
# Print the results | |
results = "Cryptsy: (" + str(cryptsyValue) + ") Bter: (" + str(bterValue) + ") MintPal: (" + str(mintpalValue) + ") Vircurex: (" + str(vircurexValue) + ") " + cryptsyusdValue | |
code.say(results) | |
################################################################################ | |
@hook(cmds=["bitcoin", "btc"], rate=30) | |
def bitcoin(code, input): | |
"""bitcoin - fetches Bitcoin price from several exchanges""" | |
# BitcoinAverage and BTC-E are from hardc0re | |
# BitcoinAverage | |
site = "https://api.bitcoinaverage.com/ticker/USD/" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
bitcoinaverageValue = "$" + str(js["last"]) | |
except: | |
bitcoinaverageValue = "error" | |
# End BitcoinAverage | |
# BTC-E | |
site = "https://btc-e.com/api/2/btc_usd/ticker" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
btceValue = "$" + str(js["ticker"]["last"]) | |
except: | |
btceValue = "error" | |
results = "BitcoinAverage: (" + str(bitcoinaverageValue) + ") BTC-E: (" + str(btceValue) + ")" | |
code.say(results) | |
################################################################################ | |
@hook(cmds=["litecoin", "ltc"], rate=30) | |
def litecoin(code, input): | |
"""litecoin - fetches Litecoin price from several exchanges""" | |
# BTC-E from hardc0re | |
site = "https://btc-e.com/api/2/ltc_usd/ticker" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
btceValue = "$" + str(js["ticker"]["last"]) | |
except: | |
btceValue = "error" | |
# Cryptsy | |
site = "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=1" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
cryptsyValue = "$" + str(js["return"]["markets"]["LTC"]["lasttradeprice"]) | |
except: | |
cryptsyValue = "error" | |
results = "BTC-E: (" + str(btceValue) + ") Cryptsy: (" + cryptsyValue + ")" | |
code.say(results) | |
############################################################################### | |
@hook(cmds=["vertcoin", "vtc"], rate=30) | |
def vertcoin(code, input): | |
"""vertcoin - fetches Vertcoin price from several exchanges""" | |
# Cryptsy | |
site = "http://pubapi.cryptsy.com/api.php?method=singlemarketdata&marketid=151" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
cryptsyValue = js["return"]["markets"]["VTC"]["lasttradeprice"] | |
except: | |
cryptsyValue = "error" | |
# End Cryptsy | |
# Bter | |
site = "http://data.bter.com/api/1/ticker/vtc_btc" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
bterValue = js["last"] | |
except: | |
bterValue = "error" | |
# End Bter | |
# MintPal | |
site = "https://api.mintpal.com/v1/market/stats/vtc/btc" | |
try: | |
req = urllib2.Request(site, headers=hdr) | |
js = json.load(urllib2.urlopen(req)) | |
mintpalValue = js[0]["last_price"] | |
except: | |
mintpalValue = "error" | |
# End MintPal | |
results = "Cryptsy: (" + str(cryptsyValue) + ") Bter: (" + str(bterValue) + ") MintPal: (" + str(mintpalValue) + ")" | |
code.say(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment