Last active
November 25, 2020 21:42
-
-
Save moeskerv/a3e0c10faccd0c6c5e3faf1edd4c8f4c to your computer and use it in GitHub Desktop.
Covid19 Widget für den Kreis Borken (iOS, braucht App Scriptable), Inspiriert durch https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664
This file contains 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
// Licence: Robert Koch-Institut (RKI), dl-de/by-2-0 | |
const newCasesApiUrl = `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_COVID19/FeatureServer/0/query?f=json&where=NeuerFall%20IN(1%2C%20-1)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&outStatistics=%5B%7B%22statisticType%22%3A%22sum%22%2C%22onStatisticField%22%3A%22AnzahlFall%22%2C%22outStatisticFieldName%22%3A%22value%22%7D%5D&resultType=standard&cacheHint=true`; | |
const currentCasesUrl = `https://services2.arcgis.com/297hbk2d6K4DqSw4/arcgis/rest/services/Covid19_AGOL/FeatureServer/1/query?f=json&where=1=1&returnGeometry=false&outFields=INFIZIERTE_AKTUELL_SUM,INFIZIERTE_AKTUELL_SUM_VORTAG,INFIZIERTE,GESUNDETE,VERSTORBENE,STAND,KOMMUNE&orderByFields=DATUM%20desc,KOMMUNE%20asc&resultOffset=0&resultRecordCount=18&resultType=standard&cacheHint=true` | |
const incidenceUrl = `https://services2.arcgis.com/297hbk2d6K4DqSw4/arcgis/rest/services/Covid19_AGOL/FeatureServer/5/query?f=json&where=1=1&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&resultOffset=0&resultRecordCount=1&resultType=standard&cacheHint=true` | |
const commune1 = "Borken" | |
const commune2 = "Bocholt" | |
let widget = await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentMedium() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
function formatCommuneText(communeAttr) { | |
return communeAttr.KOMMUNE.substring(5) + ": " + communeAttr.INFIZIERTE_AKTUELL_SUM + " Vortag: " + communeAttr.INFIZIERTE_AKTUELL_SUM_VORTAG + " (" + communeAttr.INFIZIERTE + "/" + "-" + String(parseInt(communeAttr.GESUNDETE) + parseInt(communeAttr.VERSTORBENE)) + ")" | |
} | |
async function createWidget(items) { | |
let data, header, label | |
const list = new ListWidget() | |
// set widget background color | |
const bgGradient = new LinearGradient(); | |
bgGradient.locations = [0, 1]; | |
bgGradient.colors = Device.isUsingDarkAppearance() | |
? [new Color('111'), new Color('222')] | |
: [new Color('fff'), new Color('fafafa')]; | |
list.backgroundGradient = bgGradient; | |
// fetch new cases | |
data = await new Request(newCasesApiUrl).loadJSON() | |
if (!data || !data.features || !data.features.length) { | |
const errorList = new ListWidget() | |
errorList.addText("Keine Ergebnisse für die Anfrage nach den Neuinfektionen.") | |
return errorList | |
} | |
header = list.addText("🦠 Neu (DE): ".toUpperCase() + "+" + data.features[0].attributes.value.toLocaleString()) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(18) | |
list.addSpacer() | |
// fetch communities | |
data = await new Request(currentCasesUrl).loadJSON() | |
if (!data || !data.features || !data.features.length) { | |
const errorList = new ListWidget() | |
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.") | |
return errorList | |
} | |
// iterate through features | |
for (var i = 0; i < data.features.length; i++) { | |
entry = data.features[i] | |
if (entry.attributes.KOMMUNE.includes(commune1)) { | |
var commune1Attr = entry.attributes | |
} | |
else if (entry.attributes.KOMMUNE.includes(commune2)) { | |
var commune2Attr = entry.attributes | |
} | |
} | |
// get current incidence | |
data = await new Request(incidenceUrl).loadJSON() | |
const incidence = data.features[0].attributes.ZUWACHS_7_100T.toFixed(1) | |
header = list.addText("🦠 Inzidenz".toUpperCase() + " (BOR): " + incidence.replace(".", ",")) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(20) | |
if (incidence >= 50) { | |
header.textColor = Color.red() | |
} else if (incidence >= 25) { | |
header.textColor = Color.orange() | |
} | |
const city = list.addText(formatCommuneText(commune1Attr)) | |
city.centerAlignText() | |
city.font = Font.mediumSystemFont(18) | |
city.textColor = Color.gray() | |
const city2 = list.addText(formatCommuneText(commune2Attr)) | |
city2.centerAlignText() | |
city2.font = Font.mediumSystemFont(18) | |
city2.textColor = Color.gray() | |
list.addSpacer() | |
label = list.addText("letztes Update: " + commune1Attr.STAND.substr(0, 17)) | |
label.centerAlignText() | |
label.font = Font.mediumSystemFont(12) | |
return list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Schau mal hier: https://gist.github.com/moeskerv/74b48b5170b2124da37836c9a1339efb