Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyeager committed Sep 26, 2024
0 parents commit 0b559c2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
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.
52 changes: 52 additions & 0 deletions main.py
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()

0 comments on commit 0b559c2

Please sign in to comment.