-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom widget inline class #68
Comments
Why complicate things? I have converted this script to PowerShell and told YASB to return string instead of JSON. Colors green and red are defined inside the script, so YASB will show them correctly. Here is demo 2024-11-18.14-45-34.mp4This is just example you an modify this as you want .cryto-widget .icon {
color: #f5c276;
padding: 0 6px;
}
.cryto-widget .label {
padding: 0 6px;
margin: 1px;
border-radius: 6px;
} crypto:
type: "yasb.custom.CustomWidget"
options:
label: "<span>\uf15a</span> {data}"
label_alt: " <span>\uf15a</span> Semtex"
class_name: "cryto-widget"
exec_options:
run_cmd: "powershell C:\\Users\\amn\\get_btc_binance.ps1"
return_format: "string"
hide_empty: false
run_interval: 5000
callbacks:
on_left: "toggle_label" PowerShell Script # YASB custom widget script to get BTC-EUR data from Binance as string.
# Set output encoding to UTF-8 Probably not needed
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
try {
# Get BTC-EUR data from Binance
$data = Invoke-RestMethod 'https://api.binance.com/api/v3/ticker/24hr?symbol=BTCEUR'
# Calculate rounded values with strict error checking
if ($null -eq $data.priceChangePercent) { throw "Missing priceChangePercent" }
if ($null -eq $data.lastPrice) { throw "Missing lastPrice" }
$priceChange = [math]::Round([double]$data.priceChangePercent, 2)
$lastPrice = [math]::Round([double]$data.lastPrice, 2)
#Formats the last price of Bitcoin to a string with two decimal places and appends the Euro symbol.
$lastPrice = $lastPrice.ToString("N2", [System.Globalization.CultureInfo]::InvariantCulture) + "€"
# Define trend color based on price change
$trendColor = if ($priceChange -gt 0) { 'green' } else { 'red' }
# Output formatted string with HTML (UTF-8)
[Console]::WriteLine("$lastPrice <b style=""color:$trendColor"">$priceChange%</b>")
} catch {
Write-Error "Error processing data: $_"
} |
Well thanks,
I'll give it a try.
I didn't feel like complicating things according to the customWidget
documentation first example, I'm just getting a json and formatting it a
bit with jq.
I may end up using your script and start reasoning like that for the next
ones. I'm curious though. What's not working with mine ? Is it the parsing
of the html with json inserts ? Wrong escaping ?
Le lun. 18 nov. 2024, 14:49, AmN ***@***.***> a écrit :
… Why complicate things? I have converted this script to PowerShell and told
YASB to return string instead of JSON. Colors green and red are defined
inside the script, so YASB will show them correctly.
Here is demo
https://github.com/user-attachments/assets/21909cfc-23f8-4972-94f0-df69b70eb7e0
This is just example you an modify this as you want
.cryto-widget .icon {
color: #f5c276;
padding: 0 6px;
}
.cryto-widget .label {
padding: 0 6px;
margin: 1px;
border-radius: 6px;
}
crypto:
type: "yasb.custom.CustomWidget"
options:
label: "<span>\uf15a</span> {data}"
label_alt: " <span>\uf15a</span> Semtex"
class_name: "cryto-widget"
exec_options:
run_cmd: "powershell C:\\Users\\amn\\get_btc_binance.ps1"
return_format: "string"
hide_empty: false
run_interval: 5000
callbacks:
on_left: "toggle_label"
PowerShell Script
# YASB custom widget script to get BTC-EUR data from Binance as string.# Set output encoding to UTF-8 Probably not needed
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8try {
# Get BTC-EUR data from Binance
$data = Invoke-RestMethod 'https://api.binance.com/api/v3/ticker/24hr?symbol=BTCEUR'
# Calculate rounded values with strict error checking
if ($null -eq $data.priceChangePercent) { throw "Missing priceChangePercent" }
if ($null -eq $data.lastPrice) { throw "Missing lastPrice" }
$priceChange = [math]::Round([double]$data.priceChangePercent, 2)
$lastPrice = [math]::Round([double]$data.lastPrice, 2)
#Formats the last price of Bitcoin to a string with two decimal places and appends the Euro symbol.
$lastPrice = $lastPrice.ToString("N2", [System.Globalization.CultureInfo]::InvariantCulture) + "€"
# Define trend color based on price change
$trendColor = if ($priceChange -gt 0) { 'green' } else { 'red' }
# Output formatted string with HTML (UTF-8)
[Console]::WriteLine("$lastPrice <b style=""color:$trendColor"">$priceChange%</b>")
} catch {
Write-Error "Error processing data: $_"
}
—
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANAIX7RD7BCHXW7P6WORKL2BHV6NAVCNFSM6AAAAABR7PAHA2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBTGEYDGOJYGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
But how do you expect to get |
Well my bad, this was hardcoded for testing purpose and I forgot to undo before copy/pasting, Anyway that's just curiosity, I get that this is easier to create the html to be displayed directly in the script than trying to interpret json :) |
I think style needs to reload on every update to get that |
Hello, maybe it's not an issue and I'm just dumb,
I made a small btc tracker taking use of binance api and custom-widget
While it's pretty straightforward
config
styles
Don't ask me why the class_name -> crypto-widget selector doesn't work :/
bat
Output json :
Looks like that
Right now, the
<b>
part should be pretty red.while I've troubleshooted a bit and ensured the trend prop was available and my css selector was good I can't get it to work...
Is this a limitation ? a yaml typo ? or a bug in parsing ?
The text was updated successfully, but these errors were encountered: