-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0b559c2
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Quickstart | ||
|
||
``` | ||
git clone https://github.com/scottyeager/peppermint.git | ||
cd peppermint | ||
mkdir venv | ||
python3 -m venv venv | ||
pip install python-fasthtml requests | ||
python3 main.py | ||
``` | ||
|
||
A link to visit the dev server will appear in your terminal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from datetime import datetime | ||
import requests | ||
from fasthtml.common import * | ||
|
||
app, rt = fast_app(live=True) | ||
|
||
|
||
@rt("/") | ||
def get(): | ||
return Titled( | ||
"Fetch Node Minting Receipts", | ||
Form(hx_post="/submit", hx_target="#result", hx_trigger="submit")( | ||
Input(type="int", id="node_id", placeholder=42), | ||
Button("Go", type="submit"), | ||
), | ||
Div(id="result"), | ||
) | ||
|
||
|
||
@rt("/submit") | ||
def post(d: dict): | ||
try: | ||
node_id = d["node_id"] | ||
except ValueError: | ||
return "Node id should be numbers only" | ||
|
||
receipts = requests.get( | ||
f"https://alpha.minting.tfchain.grid.tf/api/v1/node/{node_id}" | ||
).json() | ||
header = Tr( | ||
Th(Strong("Period Start")), | ||
Th(Strong("Period End")), | ||
Th(Strong("Uptime")), | ||
Th(Strong("TFT Minted")), | ||
) | ||
rows = [header] | ||
for r in receipts: | ||
if "Minting" in r["receipt"]: | ||
r = r["receipt"]["Minting"] | ||
uptime = round(r["measured_uptime"] / (30.45 * 24 * 60 * 60) * 100, 2) | ||
rows.append( | ||
Tr( | ||
Td(datetime.fromtimestamp(r["period"]["start"]).date()), | ||
Td(datetime.fromtimestamp(r["period"]["end"]).date()), | ||
Td(f"{uptime}%"), | ||
Td(r["reward"]["tft"] / 1e7), | ||
) | ||
) | ||
return Table(*rows) | ||
|
||
|
||
serve() |