generated from nathanwoodburn/python-webserver-template
feat: Add mint timestamp and date to namesummary
All checks were successful
Build Docker / BuildImage (push) Successful in 32s
All checks were successful
Build Docker / BuildImage (push) Successful in 32s
This commit is contained in:
19
server.py
19
server.py
@@ -13,7 +13,7 @@ from flask import (
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
import dotenv
|
import dotenv
|
||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
@@ -340,6 +340,8 @@ def api_namesummary(name):
|
|||||||
summary = {
|
summary = {
|
||||||
"name": name,
|
"name": name,
|
||||||
"height": None,
|
"height": None,
|
||||||
|
"mintTimestamp": None,
|
||||||
|
"mintDate": None,
|
||||||
"value": None,
|
"value": None,
|
||||||
"blocksUntilExpire": None,
|
"blocksUntilExpire": None,
|
||||||
"owner": None,
|
"owner": None,
|
||||||
@@ -395,6 +397,17 @@ def api_namesummary(name):
|
|||||||
owner_data = owner_response.json()
|
owner_data = owner_response.json()
|
||||||
summary["owner"] = owner_data.get('address', None)
|
summary["owner"] = owner_data.get('address', None)
|
||||||
|
|
||||||
|
# If the height it set, get the mint time
|
||||||
|
response = requests.get(f"{HSD_URL()}/header/{summary['height']}")
|
||||||
|
if response.status_code == 200:
|
||||||
|
block_header = response.json()
|
||||||
|
print(json.dumps(block_header, indent=4))
|
||||||
|
if 'time' in block_header:
|
||||||
|
summary["mintTimestamp"] = block_header['time']
|
||||||
|
summary["mintDate"] = datetime.fromtimestamp(block_header['time'],tz=timezone.utc).isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Get resources
|
# Get resources
|
||||||
data = {
|
data = {
|
||||||
"method": "getnameresource",
|
"method": "getnameresource",
|
||||||
@@ -469,7 +482,7 @@ def api_index(catch_all=None):
|
|||||||
|
|
||||||
# region Demo routes
|
# region Demo routes
|
||||||
|
|
||||||
demo_data = {
|
DEMO_URLS = {
|
||||||
"status": "/api/v1/status",
|
"status": "/api/v1/status",
|
||||||
"chain": "/api/v1/chain",
|
"chain": "/api/v1/chain",
|
||||||
"mempool": "/api/v1/mempool",
|
"mempool": "/api/v1/mempool",
|
||||||
@@ -489,7 +502,7 @@ demo_data = {
|
|||||||
|
|
||||||
@app.route("/demo/v1/<path:api_name>")
|
@app.route("/demo/v1/<path:api_name>")
|
||||||
def demo(api_name):
|
def demo(api_name):
|
||||||
demo_url = demo_data.get(api_name, None)
|
demo_url = DEMO_URLS.get(api_name, None)
|
||||||
if not demo_url:
|
if not demo_url:
|
||||||
return render_template("404.html"), 404
|
return render_template("404.html"), 404
|
||||||
return render_template("demo.html", url=demo_url)
|
return render_template("demo.html", url=demo_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user