pyblock/pybitblock/mempoolclock.py

141 lines
5 KiB
Python
Raw Permalink Normal View History

import json
2022-03-18 18:49:32 -03:00
import os
import subprocess
2022-03-18 18:49:32 -03:00
import sys
import base64, codecs, requests
2022-03-18 18:49:32 -03:00
import time as t
from pblogo import blogo
2022-03-18 18:49:32 -03:00
from cfonts import render, say
def clear(): # clear the screen
subprocess.run(['clear'] if os.name != 'nt' else ['cls'], shell=(os.name == 'nt'))
2022-03-18 18:49:32 -03:00
def rectangle(n):
x = n - 3
y = n - x
[
print(''.join(i))
for i in
(
''*x
if i in (0,y-1)
else
(
f'{""*n}{"|"*n}{""*n}'
if i >= (n+1)/2 and i <= (1*n)/2
else
2022-03-22 23:19:24 +01:00
f'\033[A\u001b[38;5;27m{""*(x-1)}\033[A'
2022-03-18 18:49:32 -03:00
)
for i in range(y)
)
]
def pathexec():
global path
path = {"ip_port":"", "rpcuser":"", "rpcpass":"", "bitcoincli":""}
with open("config/bclock.conf", "r") as f:
pathv = json.load(f) # Load the file 'bclock.conf'
path = pathv # Copy the variable pathv to 'path'
2022-03-18 18:49:32 -03:00
def counttxs():
2022-03-21 10:27:19 -03:00
try:
block = subprocess.run([path["bitcoincli"], "getblockcount"], capture_output=True, text=True).stdout # 'getblockcount' convert to string
2022-03-20 16:58:23 -03:00
b = block
2022-03-21 10:27:19 -03:00
a = b
2022-03-20 16:58:23 -03:00
pathexec()
2022-03-21 10:27:19 -03:00
clear()
gnaa = subprocess.run([path['bitcoincli'], "getrawmempool"], capture_output=True, text=True).stdout
2022-03-20 16:58:23 -03:00
gna1 = str(gnaa)
d = json.loads(gna1)
e = len(d)
n = e / 10
2022-03-21 10:27:19 -03:00
nn = n
while True:
x = a
block = subprocess.run([path["bitcoincli"], "getblockcount"], capture_output=True, text=True).stdout # 'getblockcount' convert to string
2022-03-21 10:27:19 -03:00
b = block
pathexec()
gnaa = subprocess.run([path['bitcoincli'], "getrawmempool"], capture_output=True, text=True).stdout
2022-03-21 10:27:19 -03:00
gna1 = str(gnaa)
d = json.loads(gna1)
e = len(d)
n = e / 10
if e > nn:
clear()
2022-03-22 22:19:38 +00:00
outputtxs = render(
f'{e} txs',
colors=[settingsClock['colorA'], settingsClock['colorB']],
align='center',
font='tiny',
)
2022-03-21 10:27:19 -03:00
print("\x1b[?25l" + outputtxs)
shq = int(n)
ss = str(rectangle(shq))
qq = ss.replace("None","")
print(f"\033[A{qq}\033[A")
nn = e
if b > a:
print("\n\n\n")
output = render(str(b), colors=[settingsClock['colorA'], settingsClock['colorB']], align='center', font='tiny')
print("\a\x1b[?25l" + output)
bb = subprocess.run([path["bitcoincli"], "getbestblockhash"], capture_output=True, text=True).stdout
2022-03-21 10:27:19 -03:00
ll = bb
qq = subprocess.run([path["bitcoincli"], "getblock", ll.strip()], capture_output=True, text=True).stdout
2022-03-21 10:27:19 -03:00
yy = json.loads(qq)
mm = yy
outputtxs = render(str(mm['nTx']) + " txs", colors=[settingsClock['colorA'], settingsClock['colorB']], align='center', font='tiny')
print("\x1b[?25l" + outputtxs)
sh = int(mm['nTx']) / 10
shq = int(sh)
ss = str(rectangle(shq))
print(ss.replace("None",""))
t.sleep(5)
txs = str(mm['nTx'])
if txs == "1":
try:
2024-06-26 21:19:52 +02:00
p = subprocess.Popen(['curl', 'http://ascii.live/forrest'])
2022-03-21 10:27:19 -03:00
p.wait(5)
except subprocess.TimeoutExpired:
p.kill()
print("\033[0;37;40m\x1b[?25l")
a = b
nn = e
except Exception:
2022-03-21 10:27:19 -03:00
pass
2022-03-20 20:22:08 -03:00
2022-03-19 18:58:06 -03:00
2022-03-18 18:49:32 -03:00
settings = {"gradient":"", "design":"block", "colorA":"green", "colorB":"yellow"}
settingsClock = {"gradient":"", "colorA":"green", "colorB":"yellow"}
while True: # Loop
2022-03-18 18:50:11 -03:00
try:
2022-03-18 18:49:32 -03:00
clear()
path = {"ip_port":"", "rpcuser":"", "rpcpass":"", "bitcoincli":""}
if os.path.isfile('config/bclock.conf') or os.path.isfile('config/blnclock.conf'): # Check if the file 'bclock.conf' is in the same folder
with open("config/bclock.conf", "r") as f:
pathv = json.load(f) # Load the file 'bclock.conf'
path = pathv # Copy the variable pathv to 'path'
2022-03-18 18:49:32 -03:00
else:
blogo()
print("Welcome to \033[1;31;40mPyBLOCK\033[0;37;40m\n\n")
print("\n\tIf you are going to use your local node leave IP:PORT/USER/PASSWORD in blank.\n")
2022-03-19 01:57:07 +00:00
path[
'ip_port'
] = f'http://{input("Insert IP:PORT to access your remote Bitcoin-Cli node: ")}'
2022-03-18 18:49:32 -03:00
path['rpcuser'] = input("RPC User: ")
path['rpcpass'] = input("RPC Password: ")
print("\n\tLocal Bitcoin Node connection.\n")
2022-03-18 18:49:32 -03:00
path['bitcoincli']= input("Insert the Path to Bitcoin-Cli: ")
with open("config/bclock.conf", "w") as f:
json.dump(path, f, indent=2)
2022-03-18 18:54:37 -03:00
counttxs()
2022-03-18 18:49:32 -03:00
except Exception:
2022-03-18 18:50:11 -03:00
print("\n")
sys.exit(101)