added logging for auras and souls

This commit is contained in:
Alexander 2024-08-23 19:17:37 -04:00
parent faae7cd463
commit 825d82e5cf
2 changed files with 12 additions and 4 deletions

15
main.py
View file

@ -1,6 +1,7 @@
import asyncio
import json
import os
import re
import warnings
from datetime import datetime, timezone
from json import JSONDecodeError
@ -64,9 +65,10 @@ def output_line(log):
block_cache[block_number] = web3.eth.get_block(block_number)
# log the message and output to console
log_message(os.getenv('CHANNEL_NAME'), decoded_data[0]['args']['LogLine'])
message = "{}:{} {}".format(decoded_data[0]['args']['Aura'], decoded_data[0]['args']['Soul'], decoded_data[0]['args']['LogLine'])
log_message(os.getenv('CHANNEL_NAME'), message)
timestamp = datetime.fromtimestamp(block_cache[block_number]['timestamp'], tz=timezone.utc)
print("[{}] {}".format(timestamp.strftime("%Y-%m-%d %H:%M:%S"), decoded_data[0]['args']['LogLine']))
print("[{}] {}".format(timestamp.strftime("%Y-%m-%d %H:%M:%S"), message if os.getenv('SHOW_AURA_AND_SOUL') != '0' else decoded_data[0]['args']['LogLine']))
# save latest block number
room = json.load(open(room_file := "{}/rooms/{}.json".format(os.getenv('DATA_FOLDER'), os.getenv('CHANNEL_NAME')), 'r'))
@ -103,8 +105,13 @@ if __name__ == '__main__':
else:
# print past log to console
logs = read_file_to_list(log_file)
for log in logs:
print(log)
for i, log in enumerate(logs):
if os.getenv('SHOW_AURA_AND_SOUL') != '0':
print(log)
else:
match = re.match(r'^.*( [\d]+:[\d]+) .*$', log)
if match:
print(log.replace(match.group(1), ''))
open(room_file, 'w').write(json.dumps(room))
# check for new messages
load_chat(room['last_block'])

View file

@ -3,4 +3,5 @@ RPC_SERVER=https://rpc.pulsechain.com
LOG_CONTRACT_ADDRESS=0x7aE73C498A308247BE73688c09c96B3fd06dDB84
LOG_CONTRACT_ABI_FILE=SHIO.json
LOG_TOPIC=0x6b81130c485ac9b98332fa40c2e57900867815b0fe1497e1a168caf930fc9c9d
SHOW_AURA_AND_SOUL=0
CHANNEL_NAME=VOID