Skip to content

Commit

Permalink
Update p2poolio.py
Browse files Browse the repository at this point in the history
BREAKING CHANGE: From Version 1.1 onwards, the execution time variable will be called exectime instead of time

A `payout` object now also contains the block. Sample result:
```json
{"payout": {"amount": "0.002557338400", "timestamp": 1678782199, "block": 2841717}, "exectime": 0.03600001335144043}
```
  • Loading branch information
OlMi1 authored Mar 15, 2023
1 parent e5c4849 commit 1f52f17
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions p2poolio.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# the payout variable always holds the most recent one
# i am a cluttered mess written in like 10 minutes, so don't be too harsh :)

# View readme.md for more info & syntax

# Version 1.1

import time
import datetime
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}')
raise Exception(f'The given path does not exist! Check for {os.path.abspath(os.getcwd())}/{path}')

lines = []
payout = {}
Expand All @@ -23,7 +24,10 @@ def read(path: str = "p2pool.log", returnLines: bool = False, linelimit: int = 1
# 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", "").replace(" ", " ")
line = line.replace("\n", "")

while(" " in line): # Replace double spaces with single spaces
line = line.replace(" ", " ")

# READ AND CATEGORIZE (and declutter)
splits = line.split(" ")
Expand All @@ -38,7 +42,7 @@ def read(path: str = "p2pool.log", returnLines: bool = False, linelimit: int = 1

# 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 = (module == "P2Pool" and line.startswith("Your wallet") and "got a payout" in line and not "no shares" in line and payout == {})
hasPayout: bool = ("your wallet" in line.lower() and "got a payout of" in line.lower() and "in block" in line.lower())
payoutdata = {
"payout": hasPayout
}
Expand All @@ -57,21 +61,21 @@ def read(path: str = "p2pool.log", returnLines: bool = False, linelimit: int = 1

if (hasPayout):
payoutdata["timestamp"] = timestamp
payoutdata["block"] = int(line.split(" ")[-1])
del(payoutdata["payout"])
payout = payoutdata
else:
break

returndata = {
"payout": payout,
"time": time.time() - starttime,
"exectime": time.time() - starttime,
}

if (returnLines):
returndata["lines"] = lines

return returndata



import json
print(json.dumps(P2PoolIO.read()))

0 comments on commit 1f52f17

Please sign in to comment.