Guest User

Covid script

a guest
Mar 15th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. // change "COUNTRY" to a value from https://coronavirus-19-api.herokuapp.com/
  2.  
  3.  
  4. const COUNTRY = "Metropolitana"
  5. 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"
  6. const API__REQ = new Request(API__URL)
  7. const API__RES = await API__REQ.loadJSON()
  8. const API__DATA= API__RES.features[0].attributes
  9. log(API__DATA)
  10.  
  11. 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"
  12. const API__REQ2 = new Request(API__URL2)
  13. const API__RES2 = await API__REQ2.loadJSON()
  14. const API__DATA2= API__RES2.features[0].attributes
  15. log(API__DATA2)
  16.  
  17. const TEXT__TITLE = { default: `🦠 Santiago 🦠`, smallWidget: "Santiago" }
  18. const TEXT__CASES_ACTIVE ="Casos Activos"
  19. const TEXT__TOTAL_CASES = "Total Cases"
  20. const TEXT__CASES_TODAY = "Cases Today"
  21. const TEXT__TOTAL_DEATHS = "Muertos"
  22. const TEXT__RECOVERED = "Recovered"
  23. const TEXT__CRITICAL = "Critical"
  24.  
  25.  
  26. //Look at the log to find the correct values if they are wrong
  27. const STAT__CASES_ACTIVE= `${API__DATA2.C_ACTIVO}`
  28. const STAT__TOTAL_CASES = `${API__DATA.CASOS_CONF}`
  29. const STAT__CASES_TODAY = `${API__DATA.CASOS_NUEV}`
  30. const STAT__TOTAL_DEATHS = `${API__DATA.FALLECIDOS}`
  31. const STAT__RECOVERED = `${API__DATA.CASOS_RECU}`
  32. const STAT__CRITICAL = `${API__DATA.HOSPITALIZ}`
  33.  
  34.  
  35. const SIRI_TEXT = `There are ${STAT__TOTAL_CASES} cases in ${COUNTRY}, and ${STAT__CASES_TODAY} new cases registered today.`
  36.  
  37. const FONT__TITLE_TEXT = { COLOR: Color.black(), FAMILY: 'boldRoundedSystemFont', size: 14, OPACITY: 1 }
  38. const FONT__STAT_TEXT = { COLOR: Color.black(), FAMILY: 'ItalicSystemFont', SIZE: 8, OPACITY: 1 }
  39. const FONT__NAME_TEXT = { COLOR: Color.red(), FAMILY: 'ArialRoundedMTBold', SIZE: 8, OPACITY: 1 }
  40.  
  41.  
  42. if (true||config.runsInWidget) {
  43. let widget = createWidget()
  44.  
  45. widget.presentSmall()
  46. Script.setWidget(widget)
  47. Script.complete()
  48. } else {
  49. let table = createStatTable()
  50.  
  51. if (config.runsWithSiri) {
  52. Speech.speak(SIRI_TEXT)
  53. }
  54.  
  55. table.present(true)
  56. }
  57.  
  58. function createStatTable() {
  59. let table = new UITable()
  60.  
  61. table.showSeparators = true
  62.  
  63. table.addRow(createStatHeaderRow(TEXT__TITLE.default))
  64. table.addRow(createStatRow(TEXT__TOTAL_CASES, STAT__TOTAL_CASES))
  65. table.addRow(createStatRow(TEXT__CASES_TODAY, STAT__CASES_TODAY))
  66. table.addRow(createStatRow(TEXT__TOTAL_DEATHS, STAT__TOTAL_DEATHS))
  67. table.addRow(createStatRow(TEXT__RECOVERED, STAT__RECOVERED))
  68. table.addRow(createStatRow(TEXT__CRITICAL, STAT__CRITICAL))
  69.  
  70. return table
  71. }
  72.  
  73. function createStatHeaderRow(name) {
  74. let headerRow = new UITableRow()
  75.  
  76. headerRow.isHeader = false
  77. headerRow.addText(name)
  78.  
  79. return headerRow
  80. }
  81.  
  82. function createStatRow(name, value) {
  83. let row = new UITableRow()
  84.  
  85. row.addText(name)
  86. row.addText(value.toString()).rightAligned()
  87.  
  88. return row
  89. }
  90.  
  91. function setWidgetTextStyle(text, type) {
  92. const FONT = type === "TITLE" ? FONT__TITLE_TEXT : type === "STAT" ? FONT__STAT_TEXT : FONT__NAME_TEXT
  93.  
  94. text.fontName = FONT.FAMILY
  95. text.textColor = FONT.COLOR
  96. text.textOpacity = FONT.OPACITY
  97. text.textSize = FONT.SIZE
  98. }
  99.  
  100. function createWidget() {
  101. const widget = new ListWidget()
  102. widget.useDefaultPadding()
  103.  
  104. let fm = FileManager.iCloud();
  105. let path = fm.documentsDirectory() + "/IMAGE NAME HERE";
  106. // Image.fromFile(path) can also be used
  107. widget.backgroundImage = fm.readImage(path);
  108.  
  109.  
  110.  
  111. // Widget Title
  112. const widgetTitle = widget.addText(config.widgetFamily === "small" ? TEXT__TITLE.smallWidget : TEXT__TITLE.default)
  113. setWidgetTextStyle(widgetTitle, "TITLE")
  114. widget.addSpacer(config.widgetFamily !== "small" ? 10 : 14)
  115.  
  116.  
  117. // active cases
  118.  
  119. const casesTodayStat = widget.addText(STAT__CASES_ACTIVE)
  120. setWidgetTextStyle(casesTodayStat, 'STAT')
  121. widget.addSpacer(1)
  122. const casesTodayName = widget.addText(TEXT__CASES_ACTIVE)
  123. setWidgetTextStyle(casesTodayName, 'NAME')
  124. widget.addSpacer(config.widgetFamily !== "small" ? 10 : 14)
  125.  
  126.  
  127. if (config.widgetFamily === "large") {
  128. // Total Cases
  129. const totalCasesStat = widget.addText(STAT__TOTAL_CASES)
  130. setWidgetTextStyle(totalCasesStat, 'STAT')
  131. widget.addSpacer(0.5)
  132. const totalCasesName = widget.addText(TEXT__TOTAL_CASES)
  133. setWidgetTextStyle(totalCasesName, 'NAME')
  134. widget.addSpacer(config.widgetFamily !== "large" ? 10 : 14)
  135.  
  136.  
  137. // Critical
  138. const criticalStat = widget.addText(STAT__CRITICAL)
  139. setWidgetTextStyle(criticalStat, 'STAT')
  140. widget.addSpacer(0.5)
  141. const criticalName = widget.addText(TEXT__CRITICAL)
  142. setWidgetTextStyle(criticalName, 'NAME')
  143. widget.addSpacer(config.widgetFamily !== "medium" ? 10 : 14)
  144. }
  145.  
  146.  
  147. if (config.widgetFamily === "large") {
  148. // Recovered
  149. const recoveredStat = widget.addText(STAT__RECOVERED)
  150. setWidgetTextStyle(recoveredStat, 'STAT')
  151. widget.addSpacer(0.5)
  152. const recoveredName = widget.addText(TEXT__RECOVERED)
  153. setWidgetTextStyle(recoveredName, 'NAME')
  154. widget.addSpacer(config.widgetFamily !== "large" ? 10 : 14)
  155. }
  156.  
  157.  
  158. // Total Deaths
  159. // const totalDeathsStat = widget.addText(STAT__TOTAL_DEATHS)
  160. // setWidgetTextStyle(totalDeathsStat, 'STAT')
  161. // widget.addSpacer(0.2)
  162. // const totalDeathsName = widget.addText(TEXT__TOTAL_DEATHS)
  163. // setWidgetTextStyle(totalDeathsName, 'NAME')
  164.  
  165.  
  166. return widget
  167. }
Advertisement
Add Comment
Please, Sign In to add comment