83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
import string
|
|
from datetime import datetime
|
|
|
|
from constants import NODES_URL_LIST
|
|
from colorama import Fore, Back, Style
|
|
import httpx
|
|
import time
|
|
import re
|
|
|
|
|
|
def print_node_status(i, node_url):
|
|
result_print = ''
|
|
|
|
if i == 0:
|
|
result_print += '\n' * 50
|
|
else:
|
|
result_print += '=' * 50 + '\n'
|
|
|
|
result_print += f"{Back.MAGENTA}{Fore.WHITE}Node #{i} {Fore.YELLOW}{node_url.split('://')[-1]}{Fore.WHITE} status ({datetime.now().strftime('%H:%M:%S %d.%m')}):{Back.BLUE}{Fore.WHITE}\n"
|
|
node_info = httpx.get(f"{node_url}/api/v1/node").json()
|
|
services_status = ''
|
|
for service_key in node_info['services']:
|
|
services_status += ' ' + f"{service_key}:" + '\n'
|
|
services_status += ' ' + f"Status: {node_info['services'][service_key]['status']}" + '\n'
|
|
services_status += ' ' + f"Delay: {node_info['services'][service_key]['delay']}" + '\n'
|
|
|
|
result_print += f"""ID: {node_info['id']}
|
|
Blockchain:
|
|
Node address: {node_info['node_address']}
|
|
Master address: {node_info['master_address']}
|
|
Master state:
|
|
Indexer height: {node_info['indexer_height']}
|
|
Services:
|
|
{services_status}
|
|
"""
|
|
|
|
content_print = 'Known content:\n'
|
|
content_list = httpx.get(f"{node_url}/api/v1/content.list?store=onchain").json()
|
|
for content_cid in content_list:
|
|
if content_list[content_cid]['onchain_index'] < (node_info['indexer_height'] - 15):
|
|
continue
|
|
|
|
content_metadata = httpx.get(f"{node_url}/api/v1/content.view/{content_cid}").json()
|
|
if 'error' in content_metadata:
|
|
continue
|
|
|
|
content_print += f"{content_list[content_cid]['onchain_index']}. {content_metadata['display_options']['metadata']['name']}" + '\n'
|
|
content_print += '\t ' + f"https://tonviewer.com/{content_metadata['content_address']}" + '\n'
|
|
content_print += '\t ' + f"CID: {content_cid}" + '\n'
|
|
content_print += '\t ' + f"Indexed at {datetime.fromisoformat(content_metadata['encrypted']['created']).strftime('%H:%M:%S %d.%m.%Y')}" + '\n'
|
|
|
|
content_print = content_print.splitlines()
|
|
if result_print:
|
|
passed_id_line = False
|
|
for i, line in enumerate(result_print.splitlines()):
|
|
if line.startswith(f"ID: "):
|
|
passed_id_line = True
|
|
|
|
if not line:
|
|
print('')
|
|
else:
|
|
content_line = ('| ' + content_print.pop(0)) if (content_print and passed_id_line) else ''
|
|
line_chars = len(re.sub(r'\x1b\[[0-9;]*m', '', line))
|
|
line = line.ljust(66 + (len(line) - line_chars))
|
|
print(f"{line} {content_line}")
|
|
|
|
print(f"{Style.RESET_ALL}")
|
|
|
|
|
|
def main():
|
|
while True:
|
|
for i, node_url in enumerate(NODES_URL_LIST):
|
|
try:
|
|
print_node_status(i, node_url)
|
|
except BaseException as e:
|
|
print(f"Error while fetching node status /api/v1/node: {e}")
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|