added logging for auras and souls
This commit is contained in:
parent
faae7cd463
commit
825d82e5cf
2 changed files with 12 additions and 4 deletions
15
main.py
15
main.py
|
|
@ -1,6 +1,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
|
|
@ -64,9 +65,10 @@ def output_line(log):
|
||||||
block_cache[block_number] = web3.eth.get_block(block_number)
|
block_cache[block_number] = web3.eth.get_block(block_number)
|
||||||
|
|
||||||
# log the message and output to console
|
# 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)
|
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
|
# save latest block number
|
||||||
room = json.load(open(room_file := "{}/rooms/{}.json".format(os.getenv('DATA_FOLDER'), os.getenv('CHANNEL_NAME')), 'r'))
|
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:
|
else:
|
||||||
# print past log to console
|
# print past log to console
|
||||||
logs = read_file_to_list(log_file)
|
logs = read_file_to_list(log_file)
|
||||||
for log in logs:
|
for i, log in enumerate(logs):
|
||||||
print(log)
|
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))
|
open(room_file, 'w').write(json.dumps(room))
|
||||||
# check for new messages
|
# check for new messages
|
||||||
load_chat(room['last_block'])
|
load_chat(room['last_block'])
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@ RPC_SERVER=https://rpc.pulsechain.com
|
||||||
LOG_CONTRACT_ADDRESS=0x7aE73C498A308247BE73688c09c96B3fd06dDB84
|
LOG_CONTRACT_ADDRESS=0x7aE73C498A308247BE73688c09c96B3fd06dDB84
|
||||||
LOG_CONTRACT_ABI_FILE=SHIO.json
|
LOG_CONTRACT_ABI_FILE=SHIO.json
|
||||||
LOG_TOPIC=0x6b81130c485ac9b98332fa40c2e57900867815b0fe1497e1a168caf930fc9c9d
|
LOG_TOPIC=0x6b81130c485ac9b98332fa40c2e57900867815b0fe1497e1a168caf930fc9c9d
|
||||||
|
SHOW_AURA_AND_SOUL=0
|
||||||
CHANNEL_NAME=VOID
|
CHANNEL_NAME=VOID
|
||||||
Loading…
Reference in a new issue