moved last block save to after the message is logged
This commit is contained in:
parent
e881401c3d
commit
5046c0ade0
1 changed files with 5 additions and 5 deletions
10
main.py
10
main.py
|
|
@ -54,11 +54,6 @@ def output_line(log):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return
|
return
|
||||||
if decoded_data[0]['args']['Aura'] and decoded_data[0]['args']['Soul']:
|
if decoded_data[0]['args']['Aura'] and decoded_data[0]['args']['Soul']:
|
||||||
# save latest block number
|
|
||||||
room = json.load(open(room_file := "{}/rooms/{}.json".format(os.getenv('DATA_FOLDER'), os.getenv('CHANNEL_NAME')), 'r'))
|
|
||||||
room['last_block'] = tx_receipt['blockNumber']
|
|
||||||
open(room_file, 'w').write(json.dumps(room))
|
|
||||||
|
|
||||||
# get the block and save it to cache
|
# get the block and save it to cache
|
||||||
block_number = tx_receipt['blockNumber']
|
block_number = tx_receipt['blockNumber']
|
||||||
if block_number not in block_cache:
|
if block_number not in block_cache:
|
||||||
|
|
@ -69,6 +64,11 @@ def output_line(log):
|
||||||
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"), 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'))
|
||||||
|
room['last_block'] = tx_receipt['blockNumber']
|
||||||
|
open(room_file, 'w').write(json.dumps(room))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# create the log and rooms folder if it doesn't exist
|
# create the log and rooms folder if it doesn't exist
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue