Created
October 3, 2020 12:15
-
-
Save PtruckStar/f97c241618182abccc946aefcfdd4505 to your computer and use it in GitHub Desktop.
corona virus updates with 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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: light-gray; icon-glyph: magic; | |
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: deep-green; icon-glyph: user-md; | |
// change "country" to a value from https://coronavirus-19-api.herokuapp.com/countries/ | |
const country = "Indonesia" | |
const url = `https://coronavirus-19-api.herokuapp.com/countries/${country}` | |
const req = new Request(url) | |
const res = await req.loadJSON() | |
if (config.runsInWidget) { | |
// create and show widget | |
let widget = await createWidget("CORONAVIRUS CASES", `${res.todayCases} Today`, `${res.cases} Total`, country, `${res.deaths} Deaths`) | |
Script.setWidget(widget) | |
Script.complete() | |
}else { | |
let widget = await createWidget("CORONAVIRUS CASES", `${res.todayCases} Today`, `${res.cases} Total`, country, `${res.deaths} Deaths`) | |
widget.presentMedium() | |
} | |
async function createWidget(pretitle, title, subtitle, country, death) { | |
let w = new ListWidget() | |
let reqImg = new Request("https://i.postimg.cc/44tYzBR6/C8962-C1-C-8317-4-AAE-B157-F4082880-BEDD.jpg") | |
let bgImg = await reqImg.loadImage() | |
w.backgroundImage = bgImg | |
let gradient = new LinearGradient() | |
gradient.locations = [0, 1] | |
gradient.colors = [new Color("#0d4fff06"), new Color("#090979b3")] | |
w.backgroundGradient = gradient | |
//padding styling | |
w.setPadding(15, 15, 5, 10) | |
let preTxt = w.addText(pretitle) | |
preTxt.textColor = Color.white() | |
preTxt.textOpacity = 0.8 | |
preTxt.font = Font.systemFont(10) | |
w.addSpacer(5) | |
let titleTxt = w.addText(title) | |
titleTxt.textColor = Color.white() | |
titleTxt.font = Font.systemFont(22) | |
w.addSpacer(3) | |
let deathTxt = w.addText(death) | |
deathTxt.textColor = Color.white() | |
deathTxt.font = Font.boldSystemFont(26) | |
w.addSpacer(3) | |
let subTxt = w.addText(subtitle) | |
subTxt.textColor = Color.white() | |
subTxt.textOpacity = 0.8 | |
subTxt.font = Font.systemFont(18) | |
w.addSpacer() | |
let bottomTxt = w.addText(`${country} COVID stats`) | |
bottomTxt.rightAlignText() | |
bottomTxt.textColor = new Color("#ffffff", 0.5) | |
// bottomTxt.textOpacity = 0.5 | |
bottomTxt.font = Font.systemFont(14) | |
return w | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment