Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CovidHU Scriptable
- const url = "https://coronavirus-19-api.herokuapp.com/countries/hungary"
- const req = new Request(url)
- const res = await req.loadJSON()
- // dark mode 0|1
- const darkMode = 0
- // lang en|hu
- const lang = "en"
- if (darkMode) {
- labelColor = Color.white()
- dataColor = Color.red()
- bgColor = Color.black()
- } else {
- labelColor = Color.black()
- dataColor = Color.red()
- bgColor = Color.white()
- }
- if (lang === "hu") {
- countryLabel = "Magyarország"
- } else {
- countryLabel = "Hungary"
- }
- if (config.runsInWidget) {
- let widget = await createWidget("COVID-19", countryLabel, `${res.todayCases}`, `${res.todayDeaths}`, `${res.critical}`, `${res.deathsPerOneMillion}`, "#fff")
- Script.setWidget(widget)
- Script.complete()
- }
- function addRow(c1, c2, label, data) {
- let lbl = c1.addText(label)
- lbl.font = Font.semiboldRoundedSystemFont(14)
- lbl.textColor = labelColor
- let dta = c2.addText(data)
- dta.rightAlignText()
- dta.font = Font.semiboldRoundedSystemFont(14)
- dta.textColor = dataColor
- }
- async function createWidget(pretitle, title, todayCases, todayDeaths, critical, deathsPerOneMillion) {
- let w = new ListWidget()
- w.backgroundColor = bgColor
- w.setPadding(10, 10, 10, 10)
- let row = w.addStack()
- let column = row.addStack()
- column.layoutVertically()
- let preText = column.addText(pretitle)
- preText.textColor = labelColor
- row.addSpacer(4)
- let titleTxt = column.addText(title)
- if (lang === "hu") {
- titleTxt.font=Font.systemFont(13)
- } else {
- titleTxt.font=Font.systemFont(16)
- }
- titleTxt.textColor = labelColor
- let req = new Request("https://i.imgur.com/cP7u2uM_d.webp")
- let icon = await req.loadImage()
- row.layoutHorizontally()
- row.addSpacer(6)
- let iconImg = row.addImage(icon)
- iconImg.imageSize = new Size(40,40)
- w.addSpacer(8)
- let cont = w.addStack()
- cont.layoutHorizontally()
- let col1 = cont.addStack()
- col1.layoutVertically()
- col1.addSpacer(4)
- let col2 = cont.addStack()
- col2.layoutVertically()
- col2.addSpacer(4)
- if (lang === "hu") {
- // HU labels
- addRow(col1, col2, "Új eset: ", todayCases)
- addRow(col1, col2, "Kritikus: ", critical)
- addRow(col1, col2, "Napi halál: ", todayDeaths)
- addRow(col1, col2, "Halál/mill.fő: ", deathsPerOneMillion)
- } else {
- addRow(col1, col2, "Today: ", todayCases)
- addRow(col1, col2, "Critical: ", critical)
- addRow(col1, col2, "Deaths: ", todayDeaths)
- addRow(col1, col2, "Deaths/mill.: ", deathsPerOneMillion)
- }
- return w
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement