Created
January 17, 2023 19:14
-
-
Save rtoscani/de7d7eb77ce23a60b1ab9e454e42bdb0 to your computer and use it in GitHub Desktop.
Dollar Blue price widget for use on scriptable
This file contains hidden or 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
const url = `https://api.bluelytics.com.ar/v2/latest`; | |
const req = new Request(url); | |
const res = await req.loadJSON(); | |
const sellAmount = res.blue.value_sell; | |
const buyAmount = res.blue.value_buy; | |
const i = new Request('https://icons.iconarchive.com/icons/designcontest/ecommerce-business/256/money-icon.png'); | |
const img = await i.loadImage(); | |
let widget = createWidget(buyAmount, sellAmount, img); | |
Script.setWidget(widget); | |
Script.complete(); | |
function createWidget(buyAmount, sellAmount, img) { | |
let w = new ListWidget(); | |
w.backgroundColor = new Color('#1A1A1A'); | |
let image = w.addImage(img); | |
image.imageSize = new Size(45, 45); | |
image.centerAlignImage(); | |
w.addSpacer(8); | |
let staticText = w.addText('Dolar Blue:'); | |
staticText.textColor = Color.white(); | |
staticText.font = Font.boldSystemFont(12); | |
staticText.centerAlignText(); | |
w.addSpacer(8); | |
let amountTxt = w.addText(buyAmount + ' - ' + sellAmount); | |
amountTxt.textColor = Color.orange(); | |
amountTxt.font = Font.systemFont(16); | |
amountTxt.centerAlignText(); | |
w.addSpacer(4); | |
let descriptionValues = w.addText('Compra - Venta'); | |
descriptionValues.textColor = Color.white(); | |
descriptionValues.font = Font.systemFont(11); | |
descriptionValues.centerAlignText(); | |
w.addSpacer(8); | |
let currentDate = new Date(); | |
let lastDate = w.addDate(currentDate); | |
lastDate.textColor = Color.gray(); | |
lastDate.font = Font.mediumSystemFont(10); | |
lastDate.centerAlignText(); | |
w.setPadding(0, 0, 0, 0); | |
return w; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment