monerobux/network.py

139 lines
4.8 KiB
Python
Raw Normal View History

2017-03-21 03:59:50 +00:00
import sopel.module
import requests
import re
2018-07-28 14:00:43 +00:00
# networkurl = "http://node.marty.cf:18019/getinfo"
2018-01-24 04:49:36 +00:00
# networkurl = "http://node.xmrbackb.one:18081/getinfo"
2018-07-28 14:00:43 +00:00
# networkurl = "http://opennode.minemonero.pro:18081/getinfo"
2020-04-01 19:04:39 +00:00
# networkurl = "http://node.xmr.pt:18081/getinfo"
networkurl = "http://node.supportxmr.com:18081/getinfo"
jsonurl = "http://node.supportxmr.com:18081/json_rpc"
headers = {
'Content-Type': 'application/json',
}
requestdata = '{"jsonrpc":"2.0","id":"0","method":"get_last_block_header"}'
2017-03-21 03:59:50 +00:00
2017-04-26 04:29:09 +00:00
@sopel.module.commands('fork', 'forkening')
def fork(bot, trigger):
try:
r=requests.get(networkurl)
j=r.json()
except Exception,e:
pass
try:
2017-10-03 00:58:43 +00:00
height=j["height"]
2020-11-22 13:48:10 +00:00
forkheight=2210000
if forkheight > height:
bot.say("The current block height is {0:,}. Fork height is {1:,}. {2:,} blocks to go, happening in approximately {3:.2f} hours.".format(height,forkheight,forkheight-height,(forkheight-height)/30.0))
2017-09-17 16:36:31 +00:00
else:
bot.say("I don't know when the next fork is.")
2017-04-26 04:29:09 +00:00
except:
bot.say("Something borked -_-")
2017-03-21 03:59:50 +00:00
@sopel.module.commands('network')
def network(bot, trigger):
try:
r=requests.get(networkurl)
j=r.json()
except Exception,e:
pass
try:
2017-10-03 00:58:43 +00:00
height=j["height"]
diff=j["difficulty"]
2017-03-21 03:59:50 +00:00
hashrate=float(diff)/120
bot.say("The current block height is {0:,}. Difficulty is {1:,}. Hashrate is {2:.2f} Mh/s.".format(height,diff,hashrate/1e6))
except:
bot.say("Something borked -_-")
@sopel.module.commands('btcmempool')
def btcmempool(bot, trigger):
try:
r=requests.get('https://blockchain.info/q/unconfirmedcount')
bot.say("The current number of txs in Bitcoin's mempool is {0}".format(r.text))
except:
bot.say("Fuck you, and fuck Bitcoin too")
@sopel.module.commands('mempool')
def mempool(bot, trigger):
try:
# r=requests.get('http://node.moneroworld.com:18081/getinfo')
2018-01-24 04:49:36 +00:00
r=requests.get(networkurl)
2017-03-21 03:59:50 +00:00
j=r.json()
bot.say("The current number of txs in Monero's mempool is {0}".format(j['tx_pool_size']))
except:
bot.say("Something borked o_O")
2021-03-30 16:20:43 +00:00
@sopel.module.commands('lastblock')
2021-03-30 16:40:55 +00:00
def lastblock(bot, trigger):
2021-03-30 16:20:43 +00:00
try:
r=requests.get(lastblock)
r=requests.post(jsonurl, headers=headers, data=requestdata)
2021-03-30 16:20:43 +00:00
j=r.json()
block=j['result']['block_header']
bot.say("Last block height is {0} with {1} transactions".format(block['height'],block['num_txes']))
2021-03-30 16:20:43 +00:00
except:
bot.say("Something borked o_O")
2017-03-21 03:59:50 +00:00
@sopel.module.commands('blocksize')
def blocksize(bot, trigger):
try:
r=requests.get('http://moneroblocks.info/stats/block-medians')
2017-04-26 04:29:09 +00:00
size=re.search('&nbsp;<\/strong><\/div>\s*<div class=\"col-xs-2\">(\d*)', r.text)
2017-03-21 03:59:50 +00:00
bot.say("Median blocksize over last 200 blocks is {0} bytes".format(size.group(1)))
except:
bot.say("Bomething sorked 0_0")
2017-10-19 02:25:13 +00:00
2017-11-25 21:43:51 +00:00
@sopel.module.commands('mine')
def mine(bot, trigger):
2017-10-19 02:25:13 +00:00
try:
2017-11-25 21:43:51 +00:00
r=requests.get('https://supportxmr.com/api/network/stats')
2017-10-19 02:25:13 +00:00
j=r.json()
2017-11-25 21:43:51 +00:00
diff=float(j['difficulty'])
value=float(j['value'])/1e12
hashrate=float(trigger.group(2))
xmrperday=(hashrate/(diff/120))*720*value
bot.say("At {:.0f} h/s with network diff of {:.2e} and block reward {:.2f} you can expect {:.4f} XMR per day.".format(hashrate, diff, value, xmrperday))
2017-10-19 02:25:13 +00:00
except:
2017-11-25 21:43:51 +00:00
bot.say("Mining is for suckers.")
2018-01-02 05:18:11 +00:00
@sopel.module.commands('solo')
def solo(bot, trigger):
try:
r=requests.get('https://supportxmr.com/api/network/stats')
j=r.json()
diff=float(j['difficulty'])
hashrate=float(trigger.group(2))
timetoblock=(diff/hashrate)
bot.say("At {:.0f} h/s with network diff of {:.2e} your expected time for find a block is {:.2e} s or {:.2f} days.".format(hashrate, diff, timetoblock, timetoblock/(60*60*24)))
except:
bot.say("Mining is for suckers.")
2017-11-25 21:43:51 +00:00
@sopel.module.commands('b2x')
def b2x(bot, trigger):
bot.say("Fuck off \\x")
2020-09-23 23:58:35 +00:00
def get_pools(coin = 'monero'):
resp = requests.get("https://data.miningpoolstats.stream/data/time")
time = int(resp.text)
resp = requests.get("https://data.miningpoolstats.stream/data/{}.js?t={}".format(coin, time))
j = resp.json()
return j
@sopel.module.commands('miners')
def print_monero_miners_counter(bot, trigger):
pools = get_pools()
result = {
'website counter': pools['poolsminers'],
'website counter recalculated': sum([
e['miners'] if ('miners' in e and isinstance(e['miners'], int) and e['miners'] >= 0) else (
e['workers'] if ('workers' in e and isinstance(e['workers'], int) and e['workers'] >= 0) else (
0
)
)
for e in pools['data']
]),
'count(miners) where miners >= 0': sum([e['miners'] for e in pools['data'] if 'miners' in e and isinstance(e['miners'], int) and e['miners'] > 0]),
'count(workers) where workers >= 0': sum([e['workers'] for e in pools['data'] if 'workers' in e and isinstance(e['workers'], int) and e['workers'] > 0]),
}
bot.say(result)