Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const widget = new ListWidget()
widget.backgroundColor = new Color('#3e9cbf')
const title = widget.addText('🇭🇷 Covid-19')
title.leftAlignText()
title.font = Font.boldSystemFont(16)
widget.addSpacer()
const url = 'https://www.koronavirus.hr/json/?action=podaci_zadnji'
const req= new Request(url)
const data = await req.loadJSON()
// get the desired data. in this case it's the first and only item
const stats = data[0]
const statsFont = Font.systemFont(14)
// get the number of cases in Croatia
const cases = stats.SlucajeviHrvatska
const casesStack = widget.addStack()
casesStack.layoutHorizontally()
const casesLabel = casesStack.addText('Slucajevi')
casesLabel.font = statsFont
casesStack.addSpacer()
const casesCount = casesStack.addText(new Intl.NumberFormat().format(stats.SlucajeviHrvatska))
casesCount.font = statsFont
const deathStack = widget.addStack()
const deathLabel = deathStack.addText('Umrli')
deathLabel.font = statsFont
deathStack.addSpacer()
const deathCount = deathStack.addText(new Intl.NumberFormat().format(stats.UmrliHrvatska))
deathCount.font = statsFont
const healedStack = widget.addStack()
healedStack.layoutHorizontally()
const healedLabel = healedStack.addText('Izlijeceni')
healedLabel.font = statsFont
healedStack.addSpacer()
const healedCount = healedStack.addText(new Intl.NumberFormat().format(stats.IzlijeceniHrvatska))
healedCount.font = statsFont
widget.addSpacer()
Script.setWidget(widget)
await widget.presentSmall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment