Added refresh time to gerty settings

This commit is contained in:
Black Coffee 2022-09-29 15:08:01 +01:00
parent c0edd15edb
commit 55de179730
4 changed files with 58 additions and 45 deletions

View file

@ -6,6 +6,7 @@ async def m001_initial(db):
"""
CREATE TABLE gerty.gertys (
id TEXT PRIMARY KEY,
refresh_time INT,
name TEXT NOT NULL,
wallet TEXT NOT NULL,
lnbits_wallets TEXT,

View file

@ -8,6 +8,7 @@ class Gerty(BaseModel):
id: str = Query(None)
name: str
wallet: str
refresh_time: int = Query(None)
lnbits_wallets: str = Query(None) # Wallets to keep an eye on, {"wallet-id": "wallet-read-key, etc"}
mempool_endpoint: str = Query(None) # Mempool endpoint to use
exchange: str = Query(None) # BTC <-> Fiat exchange rate to pull ie "USD", in 0.0001 and sats

View file

@ -164,6 +164,15 @@
<q-tooltip>Used for getting onchain/ln stats</q-tooltip>
</q-input>
<q-input
filled
dense
v-model.trim="formDialog.data.refresh_time"
label="Refresh time in seconds"
>
<q-tooltip>The amount of time in seconds between screen updates</q-tooltip>
</q-input>
<p>Use the toggles below to control what your Gerty will display</p>
<q-expansion-item
@ -608,6 +617,7 @@
},
lnbits_wallets: [],
mempool_endpoint: "https://mempool.space",
refresh_time: 300,
}
}
}
@ -621,6 +631,7 @@
this.formDialog.data = {
lnbits_wallets: [],
mempool_endpoint: "https://mempool.space",
refresh_time: 300,
display_preferences: {},
}
},
@ -646,11 +657,10 @@
this.formDialog.data.wallet = gerty.wallet
this.formDialog.data.lnbits_wallets = JSON.parse(gerty.lnbits_wallets)
this.formDialog.data.exchange = gerty.exchange,
this.formDialog.data.mempool_endpoint = gerty.mempool_endpoint,
this.formDialog.data.display_preferences = JSON.parse(gerty.display_preferences),
this.formDialog.show = true
console.log('updateformDialog', this.formDialog.data)
this.formDialog.data.mempool_endpoint = gerty.mempool_endpoint,
this.formDialog.data.refresh_time = gerty.refresh_time,
this.formDialog.data.display_preferences = JSON.parse(gerty.display_preferences),
this.formDialog.show = true
},
sendFormDataGerty: function () {
if (this.formDialog.data.id) {
@ -673,6 +683,7 @@
lnbits_wallets: JSON.stringify(this.formDialog.data.lnbits_wallets),
exchange: this.formDialog.data.exchange,
mempool_endpoint: this.formDialog.data.mempool_endpoint,
refresh_time: this.formDialog.data.refresh_time,
display_preferences: JSON.stringify(this.formDialog.data.display_preferences)
}
console.log('createGerty', data)

View file

@ -116,50 +116,50 @@ async def api_gerty_json(
#Get Satoshi quotes
satoshi = []
if gerty.sats_quote:
quote = await api_gerty_satoshi()
if quote:
satoshi.append(await api_gerty_satoshi())
# if gerty.sats_quote:
# quote = await api_gerty_satoshi()
# if quote:
# satoshi.append(await api_gerty_satoshi())
#Get Exchange Value
exchange = []
if gerty.exchange != "":
try:
amount = await satoshis_amount_as_fiat(100000000, gerty.exchange)
if amount:
exchange.append({
"fiat": gerty.exchange,
"amount": amount,
})
except:
pass
# if gerty.exchange != "":
# try:
# amount = await satoshis_amount_as_fiat(100000000, gerty.exchange)
# if amount:
# exchange.append({
# "fiat": gerty.exchange,
# "amount": amount,
# })
# except:
# pass
#
# onchain = []
# if gerty.onchain_stats and isinstance(gerty.mempool_endpoint, str):
# async with httpx.AsyncClient() as client:
# difficulty = []
# r = await client.get(gerty.mempool_endpoint + "/api/v1/difficulty-adjustment")
# if r:
# difficulty.append(r.json())
# onchain.append({"difficulty":difficulty})
# mempool = []
# r = await client.get(gerty.mempool_endpoint + "/api/v1/fees/mempool-blocks")
# if r:
# mempool.append(r.json())
# onchain.append({"mempool":mempool})
# threed = []
# r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/3d")
# if r:
# threed.append(r.json())
# onchain.append({"threed":threed})
onchain = []
if gerty.onchain_stats and isinstance(gerty.mempool_endpoint, str):
async with httpx.AsyncClient() as client:
difficulty = []
r = await client.get(gerty.mempool_endpoint + "/api/v1/difficulty-adjustment")
if r:
difficulty.append(r.json())
onchain.append({"difficulty":difficulty})
mempool = []
r = await client.get(gerty.mempool_endpoint + "/api/v1/fees/mempool-blocks")
if r:
mempool.append(r.json())
onchain.append({"mempool":mempool})
threed = []
r = await client.get(gerty.mempool_endpoint + "/api/v1/mining/hashrate/3d")
if r:
threed.append(r.json())
onchain.append({"threed":threed})
# ln = []
# if gerty.ln_stats and isinstance(gerty.mempool_endpoint, str):
# async with httpx.AsyncClient() as client:
# r = await client.get(gerty.mempool_endpoint + "/api/v1/lightning/statistics/latest")
# if r:
# ln.append(r.json())
ln = []
if gerty.ln_stats and isinstance(gerty.mempool_endpoint, str):
async with httpx.AsyncClient() as client:
r = await client.get(gerty.mempool_endpoint + "/api/v1/lightning/statistics/latest")
if r:
ln.append(r.json())
return {"name":gerty.name, "wallets":wallets, "sats_quote":satoshi, "exchange":exchange, "onchain":onchain, "ln":ln}
return {"name":gerty.name}