2026-04-01 10:24:47 -03:00
import json
2021-04-13 14:10:23 -03:00
import os
2026-04-01 10:24:47 -03:00
import subprocess
2021-04-13 14:10:23 -03:00
import sys
2026-04-01 10:24:47 -03:00
import base64 , codecs , requests
2022-03-18 18:49:32 -03:00
import time as t
2021-04-13 14:10:23 -03:00
from cfonts import render , say
2022-03-18 18:49:32 -03:00
2021-04-13 14:10:23 -03:00
def clear ( ) : # clear the screen
2026-04-01 10:24:47 -03:00
subprocess . run ( [ ' clear ' ] if os . name != ' nt ' else [ ' cls ' ] , shell = ( os . name == ' nt ' ) )
2021-04-13 14:10:23 -03:00
2022-03-13 23:59:13 -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:50 +01:00
f ' \033 [A \u001b [38;5;27m { " █ " * ( x - 1 ) } \033 [A '
2022-03-13 23:59:13 -03:00
)
for i in range ( y )
)
]
2021-04-13 14:10:23 -03:00
def blogo ( ) :
2022-03-13 23:59:13 -03:00
if os . path . isfile ( ' config/pyblocksettings.conf ' ) or os . path . isfile ( ' config/pyblocksettings.conf ' ) : # Check if the file 'bclock.conf' is in the same folder
2026-04-01 11:52:26 -03:00
with open ( " config/pyblocksettings.conf " , " r " ) as f :
settingsv = json . load ( f ) # Load the file 'bclock.conf'
settings = settingsv # Copy the variable pathv to 'path'
2021-04-13 14:10:23 -03:00
else :
settings = { " gradient " : " " , " design " : " block " , " colorA " : " green " , " colorB " : " yellow " }
2026-04-01 10:24:47 -03:00
with open ( " config/pyblocksettings.conf " , " w " ) as f :
json . dump ( settings , f , indent = 2 )
2021-04-13 14:10:23 -03:00
if settings [ " gradient " ] == " grd " :
output = render ( ' PyBLOCK ' , gradient = [ settings [ ' colorA ' ] , settings [ ' colorB ' ] ] , align = ' center ' , font = settings [ ' design ' ] )
else :
output = render ( ' PyBLOCK ' , colors = [ settings [ ' colorA ' ] , settings [ ' colorB ' ] ] , align = ' center ' , font = settings [ ' design ' ] )
print ( output )
def artist ( ) : # here we convert the result of the command 'getblockcount' on a random art design
while True :
try :
clear ( )
design ( )
2026-04-01 11:52:26 -03:00
except Exception :
2021-04-13 14:10:23 -03:00
break
2022-03-18 18:49:32 -03:00
def pathexec ( ) :
global path
path = { " ip_port " : " " , " rpcuser " : " " , " rpcpass " : " " , " bitcoincli " : " " }
2026-04-01 11:52:26 -03:00
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
2021-04-13 14:10:23 -03:00
def design ( ) :
while True :
2022-03-13 23:59:13 -03:00
if os . path . isfile ( ' config/pyblocksettingsClock.conf ' ) or os . path . isfile ( ' config/pyblocksettingsClock.conf ' ) : # Check if the file 'bclock.conf' is in the same folder
2026-04-01 11:52:26 -03:00
with open ( " config/pyblocksettingsClock.conf " , " r " ) as f :
settingsv = json . load ( f ) # Load the file 'bclock.conf'
settingsClock = settingsv # Copy the variable pathv to 'path'
2021-04-13 14:10:23 -03:00
else :
settingsClock = { " gradient " : " " , " design " : " block " , " colorA " : " green " , " colorB " : " yellow " }
2026-04-01 10:24:47 -03:00
with open ( " config/pyblocksettingsClock.conf " , " w " ) as f :
json . dump ( settingsClock , f , indent = 2 )
2026-04-02 17:35:03 -03:00
block = subprocess . run ( [ path [ ' bitcoincli ' ] , ' getblockcount ' ] , capture_output = True , text = True ) . stdout # 'getblockcount' convert to string
2021-04-13 14:10:23 -03:00
b = block
a = b
blogo ( )
output = render ( str ( b ) , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' )
print ( " \x1b [?25l " + output )
2026-04-02 17:35:03 -03:00
bb = subprocess . run ( [ path [ ' bitcoincli ' ] , ' getbestblockhash ' ] , capture_output = True , text = True ) . stdout
2021-04-13 14:10:23 -03:00
ll = bb
2026-04-02 17:35:03 -03:00
qq = subprocess . run ( [ path [ ' bitcoincli ' ] , ' getblock ' , ll . strip ( ) ] , capture_output = True , text = True ) . stdout
2021-04-13 14:10:23 -03:00
yy = json . loads ( qq )
mm = yy
2022-03-13 23:59:13 -03:00
outputsize = render ( str ( mm [ ' size ' ] ) + " bytes " , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' , font = ' tiny ' )
2021-04-13 14:10:23 -03:00
print ( " \x1b [?25l " + outputsize )
2022-03-13 23:59:13 -03:00
outputtxs = render ( str ( mm [ ' nTx ' ] ) + " txs " , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' , font = ' tiny ' )
2021-04-13 14:10:23 -03:00
print ( " \x1b [?25l " + outputtxs )
2022-03-13 23:59:13 -03:00
sh = int ( mm [ ' nTx ' ] ) / 4
shq = int ( sh )
ss = str ( rectangle ( shq ) )
print ( ss . replace ( " None " , " " ) )
2021-04-13 14:10:23 -03:00
while True :
x = a
2026-04-02 17:35:03 -03:00
block = subprocess . run ( [ path [ ' bitcoincli ' ] , ' getblockcount ' ] , capture_output = True , text = True ) . stdout # 'getblockcount' convert to string
2021-04-13 14:10:23 -03:00
b = block
if b > a :
clear ( )
blogo ( )
output = render ( str ( b ) , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' )
print ( " \a \x1b [?25l " + output )
2026-04-02 17:35:03 -03:00
bb = subprocess . run ( [ path [ ' bitcoincli ' ] , ' getbestblockhash ' ] , capture_output = True , text = True ) . stdout
2021-04-13 14:10:23 -03:00
ll = bb
2026-04-02 17:35:03 -03:00
qq = subprocess . run ( [ path [ ' bitcoincli ' ] , ' getblock ' , ll . strip ( ) ] , capture_output = True , text = True ) . stdout
2021-04-13 14:10:23 -03:00
yy = json . loads ( qq )
mm = yy
2022-03-13 23:59:13 -03:00
outputsize = render ( str ( mm [ ' size ' ] ) + " bytes " , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' , font = ' tiny ' )
2021-04-13 14:10:23 -03:00
print ( " \x1b [?25l " + outputsize )
2022-03-13 23:59:13 -03:00
outputtxs = render ( str ( mm [ ' nTx ' ] ) + " txs " , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' , font = ' tiny ' )
2021-04-13 14:10:23 -03:00
print ( " \x1b [?25l " + outputtxs )
2022-03-13 23:59:13 -03:00
sh = int ( mm [ ' nTx ' ] ) / 4
shq = int ( sh )
ss = str ( rectangle ( shq ) )
print ( ss . replace ( " None " , " " ) )
2021-04-13 14:10:23 -03:00
t . sleep ( 10 )
2022-03-07 03:07:14 +01:00
txs = str ( mm [ ' nTx ' ] )
if txs == " 1 " :
2022-03-08 00:13:31 +01:00
try :
2024-06-26 21:20:24 +02:00
p = subprocess . Popen ( [ ' curl ' , ' http://ascii.live/forrest ' ] )
2022-03-08 00:13:31 +01:00
p . wait ( 5 )
except subprocess . TimeoutExpired :
p . kill ( )
print ( " \033 [0;37;40m \x1b [?25l " )
2021-04-13 14:10:23 -03:00
clear ( )
2022-03-08 00:13:31 +01:00
close ( )
2021-04-13 14:10:23 -03:00
a = b
output = render ( str ( b ) , colors = [ settingsClock [ ' colorA ' ] , settingsClock [ ' colorB ' ] ] , align = ' center ' )
print ( " \x1b [?25l " + output )
settings = { " gradient " : " " , " design " : " block " , " colorA " : " green " , " colorB " : " yellow " }
settingsClock = { " gradient " : " " , " colorA " : " green " , " colorB " : " yellow " }
while True : # Loop
try :
clear ( )
path = { " ip_port " : " " , " rpcuser " : " " , " rpcpass " : " " , " bitcoincli " : " " }
2022-03-13 23:59:13 -03:00
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
2026-04-01 11:52:26 -03:00
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'
2021-04-13 14:10:23 -03:00
else :
blogo ( )
print ( " Welcome to \033 [1;31;40mPyBLOCK \033 [0;37;40m \n \n " )
print ( " \n \t If you are going to use your local node leave IP:PORT/USER/PASSWORD in blank. \n " )
2022-03-22 22:20:03 +00:00
path [
' ip_port '
] = f ' http:// { input ( " Insert IP:PORT to access your remote Bitcoin-Cli node: " ) } '
2021-04-13 14:10:23 -03:00
path [ ' rpcuser ' ] = input ( " RPC User: " )
path [ ' rpcpass ' ] = input ( " RPC Password: " )
2026-03-21 04:10:09 +01:00
print ( " \n \t Local Bitcoin Node connection. \n " )
2021-04-13 14:10:23 -03:00
path [ ' bitcoincli ' ] = input ( " Insert the Path to Bitcoin-Cli: " )
2026-04-01 10:24:47 -03:00
with open ( " config/bclock.conf " , " w " ) as f :
json . dump ( path , f , indent = 2 )
2021-04-13 14:10:23 -03:00
artist ( )
2026-04-01 11:52:26 -03:00
except Exception :
2021-04-13 14:10:23 -03:00
print ( " \n " )
sys . exit ( 101 )