-
-
Save Wdavery/c5b879248b4fe691897103825e01aa4f to your computer and use it in GitHub Desktop.
Canadian COVID-19 Daily Cases Scriptable Widget
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: deep-green; icon-glyph: user-md; | |
// change "country" to a value from https://coronavirus-19-api.herokuapp.com/countries/ | |
const url = `https://api.covid19tracker.ca/summary/split` | |
const req = new Request(url) | |
const res = await req.loadJSON() | |
const url2 = `https://api.covid19tracker.ca/summary` | |
const req2 = new Request(url2) | |
const res2 = await req2.loadJSON() | |
if (config.runsInWidget) { | |
// create and show widget | |
// let widget = createWidget("COVID Stats", "Ontario", `+${res.data[0].change_cases} Today\n${res.data[0].total_cases} Total`, "Canada", `+${res2.data[0].change_cases} Today\n${res2.data[0].total_cases} Total`, `${res.last_updated}`, "#f4b2b2") | |
let widget = createWidget("COVID Stats", "Ontario", `+${res.data[0].change_cases} Today`, "Canada", `+${res2.data[0].change_cases} Today`, `${res.last_updated}`, "#c9a3a3") | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
// make table | |
let table = new UITable() | |
// add header | |
let row = new UITableRow() | |
row.isHeader = true | |
row.addText(`Coronavirus Stats in ${country}`) | |
table.addRow(row) | |
// fill data | |
table.addRow(createRow("Today", res2.data[0].change_cases)) | |
table.addRow(createRow("Cases", res2.data[0].total_cases)) | |
table.addRow(createRow("Recovered", res2.data[0].total_recoveries)) | |
table.addRow(createRow("Critical", res2.data[0].total_criticals)) | |
table.addRow(createRow("Deaths", res2.data[0].total_fatalities)) | |
table.addRow(createRow("Last Updated", res2.last_updated)) | |
if (config.runsWithSiri) | |
Speech.speak(`There are ${res2.total_cases} cases in ${country}, and ${res2.change_cases} cases today.`) | |
// present table | |
table.present() | |
} | |
function createRow(title, number) { | |
let row = new UITableRow() | |
row.addText(title) | |
row.addText(number.toString()).rightAligned() | |
return row | |
} | |
function createWidget(pretitle, province, provstat, nation, canstat, updated, color) { | |
var uptime = `Updated: ` + updated.substring(updated.length - 8, updated.length -3) | |
let w = new ListWidget() | |
w.backgroundColor = new Color(color) | |
let preTxt = w.addText(pretitle) | |
preTxt.textColor = Color.white() | |
preTxt.textOpacity = 0.9 | |
preTxt.font = Font.systemFont(14) | |
w.addSpacer(6) | |
let provTxt = w.addText(province) | |
provTxt.textColor = Color.white() | |
provTxt.textOpacity = 0.9 | |
provTxt.font = Font.systemFont(10) | |
let provstatTxt = w.addText(provstat) | |
provstatTxt.textColor = Color.white() | |
provstatTxt.textOpacity = 1 | |
provstatTxt.font = Font.systemFont(15) | |
w.addSpacer(4) | |
let natTxt = w.addText(nation) | |
natTxt.textColor = Color.white() | |
natTxt.textOpacity = 0.9 | |
natTxt.font = Font.systemFont(10) | |
let canstatTxt = w.addText(canstat) | |
canstatTxt.textColor = Color.white() | |
canstatTxt.textOpacity = 1 | |
canstatTxt.font = Font.systemFont(15) | |
w.addSpacer(8) | |
let upTxt = w.addText(uptime) | |
upTxt.textColor = Color.white() | |
upTxt.textOpacity = 0.8 | |
upTxt.font = Font.systemFont(10) | |
return w | |
} |
Author
Wdavery
commented
Oct 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment