-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataparsing.py
64 lines (51 loc) · 2 KB
/
dataparsing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import time
import datetime
import KeyScraper
from console import *
data_colors = {
'lock': Colors.GREEN_BOLD,
'unlock': Colors.BLUE_BOLD_BRIGHT,
'add-key': Colors.YELLOW_BOLD_BRIGHT,
'revoke-key': Colors.BLACK_BOLD_BRIGHT,
'login': Colors.CYAN_BOLD_BRIGHT,
'kick': Colors.RED_BOLD_BRIGHT
}
def log(key: str, typ: str):
with open('log.json', mode='r+', encoding='utf-8') as f:
data = json.load(f)
data.append({
"key": key,
"keyname": KeyScraper.keynames[key] if key in KeyScraper.keynames else 'N/A',
"timestamp": datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'),
"type": typ
})
f.seek(0)
json.dump(data[:min(len(data), 50)], f, indent=4)
f.truncate()
def clear_log():
with open('log.json', 'w') as f:
json.dump([], f)
def print_log():
Console.clear()
with open('log.json', mode='r+', encoding='utf-8') as f:
data = json.load(f)
Console.print('BLOCKCHAINCHAIN SYSTEM LOG')
Console.print(f'╔═{"═" * 50}═╦═{"═" * 19}═╦═{"═" * 19}═╦═{"═" * 12}═╗', Colors.BLACK_BOLD)
Console.print(f'║ {"Key":<50} ║ {"Key File":19} ║ {"Timestamp":19} ║ {"Type":12} ║', Colors.BLACK_BOLD)
Console.print(f'╠═{"═" * 50}═╬═{"═" * 19}═╬═{"═" * 19}═╬═{"═" * 12}═╣', Colors.BLACK_BOLD)
for t in data:
Console.print(f'║ {t["key"]:<50} ║ {t["keyname"]:19} ║ {t["timestamp"].upper():19} ║ {t["type"].upper():12} ║',
data_colors[t['type'].lower()])
Console.print(f'╚═{"═" * 50}═╩═{"═" * 19}═╩═{"═" * 19}═╩═{"═" * 12}═╝', Colors.BLACK_BOLD)
"╚═══╩═══╩═══╝"
if __name__ == '__main__':
clear_log()
"""
log('one', 'lock/unlock')
log('two', 'add-key')
log('three', 'revoke-key')
log('four', 'login')
log('five', 'kick')
print_log()
"""