Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createWidget(district, newInfections, last_update, cases) {
- let widget = new ListWidget()
- let title = widget.addText(district)
- title.font = Font.boldSystemFont(16)
- title.minimumScaleFactor = 0.8
- title.lineLimit = 2
- let subTitle = widget.addText("7-Tage-Inzidenz")
- subTitle.font = Font.regularSystemFont(14)
- subTitle.textColor = Color.gray()
- widget.addSpacer()
- let infections = widget.addText(newInfections.toFixed(1))
- infections.font = Font.regularSystemFont(36)
- infections.centerAlignText()
- if (newInfections > 50) {
- infections.textColor = Color.red()
- } else if (newInfections > 0) {
- infections.textColor = Color.orange()
- }
- widget.addSpacer()
- let footer2 = widget.addText(cases+" Fälle")
- footer2.minimumScaleFactor = 0.5
- footer2.lineLimit = 1
- footer2.textColor = Color.gray()
- let footer = widget.addText(last_update)
- footer.minimumScaleFactor = 0.5
- footer.lineLimit = 1
- footer.textColor = Color.gray()
- return widget
- }
- async function getData(objectID) {
- 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`)
- let response = await req.loadJSON()
- return response.features[0].attributes
- }
- if (config.runsInApp) {
- // Demo for in-app testing
- let data = await getData(186)
- let widget = createWidget(data.county, data.cases7_per_100k, data.last_update, data.cases)
- widget.presentSmall()
- } else {
- // The real deal
- let objectID = args.widgetParameter
- let data = await getData(objectID)
- let widget = createWidget(data.county, data.cases7_per_100k, data.last_update, data.cases)
- Script.setWidget(widget)
- }
Add Comment
Please, Sign In to add comment