Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // change "COUNTRY" to a value from https://coronavirus-19-api.herokuapp.com/
- const COUNTRY = "Metropolitana"
- const API__URL = "https://services3.arcgis.com/YLNLlpguFsVmgseb/arcgis/rest/services/tabla_dato_regional/FeatureServer/0/query?f=json&where=CUT_REG%3D%2713%27&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=ID%20desc&resultOffset=0&resultRecordCount=1&resultType=standard&cacheHint=true"
- const API__REQ = new Request(API__URL)
- const API__RES = await API__REQ.loadJSON()
- const API__DATA= API__RES.features[0].attributes
- log(API__DATA)
- const API__URL2 = "https://services3.arcgis.com/YLNLlpguFsVmgseb/arcgis/rest/services/Dato_por_comuna_EPI_VISTA/FeatureServer/0/query?f=json&where=CUT_REG%3D%2713%27&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=ID%20desc&resultOffset=0&resultRecordCount=1&resultType=standard&cacheHint=true"
- const API__REQ2 = new Request(API__URL2)
- const API__RES2 = await API__REQ2.loadJSON()
- const API__DATA2= API__RES2.features[0].attributes
- log(API__DATA2)
- const TEXT__TITLE = { default: `🦠Santiago 🦠`, smallWidget: "Santiago" }
- const TEXT__CASES_ACTIVE ="Casos Activos"
- const TEXT__TOTAL_CASES = "Total Cases"
- const TEXT__CASES_TODAY = "Cases Today"
- const TEXT__TOTAL_DEATHS = "Muertos"
- const TEXT__RECOVERED = "Recovered"
- const TEXT__CRITICAL = "Critical"
- //Look at the log to find the correct values if they are wrong
- const STAT__CASES_ACTIVE= `${API__DATA2.C_ACTIVO}`
- const STAT__TOTAL_CASES = `${API__DATA.CASOS_CONF}`
- const STAT__CASES_TODAY = `${API__DATA.CASOS_NUEV}`
- const STAT__TOTAL_DEATHS = `${API__DATA.FALLECIDOS}`
- const STAT__RECOVERED = `${API__DATA.CASOS_RECU}`
- const STAT__CRITICAL = `${API__DATA.HOSPITALIZ}`
- const SIRI_TEXT = `There are ${STAT__TOTAL_CASES} cases in ${COUNTRY}, and ${STAT__CASES_TODAY} new cases registered today.`
- const FONT__TITLE_TEXT = { COLOR: Color.black(), FAMILY: 'boldRoundedSystemFont', size: 14, OPACITY: 1 }
- const FONT__STAT_TEXT = { COLOR: Color.black(), FAMILY: 'ItalicSystemFont', SIZE: 8, OPACITY: 1 }
- const FONT__NAME_TEXT = { COLOR: Color.red(), FAMILY: 'ArialRoundedMTBold', SIZE: 8, OPACITY: 1 }
- if (true||config.runsInWidget) {
- let widget = createWidget()
- widget.presentSmall()
- Script.setWidget(widget)
- Script.complete()
- } else {
- let table = createStatTable()
- if (config.runsWithSiri) {
- Speech.speak(SIRI_TEXT)
- }
- table.present(true)
- }
- function createStatTable() {
- let table = new UITable()
- table.showSeparators = true
- table.addRow(createStatHeaderRow(TEXT__TITLE.default))
- table.addRow(createStatRow(TEXT__TOTAL_CASES, STAT__TOTAL_CASES))
- table.addRow(createStatRow(TEXT__CASES_TODAY, STAT__CASES_TODAY))
- table.addRow(createStatRow(TEXT__TOTAL_DEATHS, STAT__TOTAL_DEATHS))
- table.addRow(createStatRow(TEXT__RECOVERED, STAT__RECOVERED))
- table.addRow(createStatRow(TEXT__CRITICAL, STAT__CRITICAL))
- return table
- }
- function createStatHeaderRow(name) {
- let headerRow = new UITableRow()
- headerRow.isHeader = false
- headerRow.addText(name)
- return headerRow
- }
- function createStatRow(name, value) {
- let row = new UITableRow()
- row.addText(name)
- row.addText(value.toString()).rightAligned()
- return row
- }
- function setWidgetTextStyle(text, type) {
- const FONT = type === "TITLE" ? FONT__TITLE_TEXT : type === "STAT" ? FONT__STAT_TEXT : FONT__NAME_TEXT
- text.fontName = FONT.FAMILY
- text.textColor = FONT.COLOR
- text.textOpacity = FONT.OPACITY
- text.textSize = FONT.SIZE
- }
- function createWidget() {
- const widget = new ListWidget()
- widget.useDefaultPadding()
- let fm = FileManager.iCloud();
- let path = fm.documentsDirectory() + "/IMAGE NAME HERE";
- // Image.fromFile(path) can also be used
- widget.backgroundImage = fm.readImage(path);
- // Widget Title
- const widgetTitle = widget.addText(config.widgetFamily === "small" ? TEXT__TITLE.smallWidget : TEXT__TITLE.default)
- setWidgetTextStyle(widgetTitle, "TITLE")
- widget.addSpacer(config.widgetFamily !== "small" ? 10 : 14)
- // active cases
- const casesTodayStat = widget.addText(STAT__CASES_ACTIVE)
- setWidgetTextStyle(casesTodayStat, 'STAT')
- widget.addSpacer(1)
- const casesTodayName = widget.addText(TEXT__CASES_ACTIVE)
- setWidgetTextStyle(casesTodayName, 'NAME')
- widget.addSpacer(config.widgetFamily !== "small" ? 10 : 14)
- if (config.widgetFamily === "large") {
- // Total Cases
- const totalCasesStat = widget.addText(STAT__TOTAL_CASES)
- setWidgetTextStyle(totalCasesStat, 'STAT')
- widget.addSpacer(0.5)
- const totalCasesName = widget.addText(TEXT__TOTAL_CASES)
- setWidgetTextStyle(totalCasesName, 'NAME')
- widget.addSpacer(config.widgetFamily !== "large" ? 10 : 14)
- // Critical
- const criticalStat = widget.addText(STAT__CRITICAL)
- setWidgetTextStyle(criticalStat, 'STAT')
- widget.addSpacer(0.5)
- const criticalName = widget.addText(TEXT__CRITICAL)
- setWidgetTextStyle(criticalName, 'NAME')
- widget.addSpacer(config.widgetFamily !== "medium" ? 10 : 14)
- }
- if (config.widgetFamily === "large") {
- // Recovered
- const recoveredStat = widget.addText(STAT__RECOVERED)
- setWidgetTextStyle(recoveredStat, 'STAT')
- widget.addSpacer(0.5)
- const recoveredName = widget.addText(TEXT__RECOVERED)
- setWidgetTextStyle(recoveredName, 'NAME')
- widget.addSpacer(config.widgetFamily !== "large" ? 10 : 14)
- }
- // Total Deaths
- // const totalDeathsStat = widget.addText(STAT__TOTAL_DEATHS)
- // setWidgetTextStyle(totalDeathsStat, 'STAT')
- // widget.addSpacer(0.2)
- // const totalDeathsName = widget.addText(TEXT__TOTAL_DEATHS)
- // setWidgetTextStyle(totalDeathsName, 'NAME')
- return widget
- }
Advertisement
Add Comment
Please, Sign In to add comment