-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2poolio.py
81 lines (62 loc) · 2.85 KB
/
p2poolio.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# the payout variable always holds the most recent one
# View readme.md for more info & syntax
# Version 1.1
import time
import os
import datetime
class P2PoolIO:
def read(path: str = "p2pool.log", returnLines: bool = False, linelimit: int = 100):
starttime = time.time()
if (not os.path.exists(path)):
raise Exception(f'The given path does not exist! Check for {os.path.abspath(os.getcwd())}/{path}')
lines = []
payout = {}
possibleTags = ["INFO", "WARN", "ERROR", "FATAL", "DEBUG", "TRACE", "NOTICE"] # thx copilot
with open(path, "r") as f:
# Read the file in reverse and add each line to the list
for line in reversed(f.readlines()):
if (len(lines) < linelimit):
line = line.replace("\n", "")
while(" " in line): # Replace double spaces with single spaces
line = line.replace(" ", " ")
# READ AND CATEGORIZE (and declutter)
splits = line.split(" ")
type = splits[0]
if (type not in possibleTags):
continue
timestamp = int(time.mktime(datetime.datetime.strptime(
f'{splits[1]} {splits[2].split(".")[0]}', "%Y-%m-%d %H:%M:%S").timetuple()))
module = splits[3]
line = " ".join(splits[4:])
# Your wallet ... didn't get a payout in block 2814592 because you had no shares in PPLNS window
# Your wallet ... got a payout of 0.12345 XMR in block 2820000
hasPayout: bool = ("your wallet" in line.lower() and "got a payout of" in line.lower() and "in block" in line.lower())
payoutdata = {
"payout": hasPayout
}
if (hasPayout):
payoutdata["amount"] = line.split("got a payout of ")[1].split(" ")[0]
added = {
"type": type,
"timestamp": timestamp,
"module": module,
"payout": payoutdata,
"content": line
}
lines.append(added)
if (hasPayout):
payoutdata["timestamp"] = timestamp
payoutdata["block"] = int(line.split(" ")[-1])
del(payoutdata["payout"])
payout = payoutdata
else:
break
returndata = {
"payout": payout,
"exectime": time.time() - starttime,
}
if (returnLines):
returndata["lines"] = lines
return returndata
import json
print(json.dumps(P2PoolIO.read()))