Guest User

COVIDget

a guest
Oct 20th, 2020
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createWidget(district, newInfections, last_update, cases) {
  2.   let widget = new ListWidget()
  3.  
  4.   let title = widget.addText(district)
  5.   title.font = Font.boldSystemFont(16)
  6.   title.minimumScaleFactor = 0.8
  7.   title.lineLimit = 2
  8.  
  9.   let subTitle = widget.addText("7-Tage-Inzidenz")
  10.   subTitle.font = Font.regularSystemFont(14)
  11.   subTitle.textColor = Color.gray()
  12.  
  13.   widget.addSpacer()
  14.  
  15.   let infections = widget.addText(newInfections.toFixed(1))
  16.   infections.font = Font.regularSystemFont(36)
  17.   infections.centerAlignText()
  18.   if (newInfections > 50) {
  19.     infections.textColor = Color.red()
  20.   } else if (newInfections > 0) {
  21.     infections.textColor = Color.orange()
  22.   }
  23.  
  24.   widget.addSpacer()
  25.  
  26.  
  27.   let footer2 = widget.addText(cases+" Fälle")
  28.   footer2.minimumScaleFactor = 0.5
  29.   footer2.lineLimit = 1
  30.   footer2.textColor = Color.gray()  
  31.  
  32.   let footer = widget.addText(last_update)
  33.   footer.minimumScaleFactor = 0.5
  34.   footer.lineLimit = 1
  35.   footer.textColor = Color.gray()
  36.  
  37.   return widget
  38. }
  39.  
  40. async function getData(objectID) {
  41.   let req = new Request(`https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=OBJECTID%3D${186}&outFields=OBJECTID,GEN,BEZ,IBZ,cases,deaths,county,last_update,cases7_per_100k,recovered,cases7_bl_per_100k&outSR=4326&f=json`)
  42.   let response = await req.loadJSON()
  43.   return response.features[0].attributes
  44. }
  45.  
  46. if (config.runsInApp) {
  47.   // Demo for in-app testing
  48.   let data = await getData(186)
  49.   let widget = createWidget(data.county, data.cases7_per_100k, data.last_update, data.cases)
  50.   widget.presentSmall()
  51. } else {
  52.   // The real deal
  53.   let objectID = args.widgetParameter
  54.   let data = await getData(objectID)
  55.   let widget = createWidget(data.county, data.cases7_per_100k, data.last_update, data.cases)
  56.   Script.setWidget(widget)
  57. }
Add Comment
Please, Sign In to add comment