-
-
Save malakka/0576bb922e7b81b95137a06b619bba1b to your computer and use it in GitHub Desktop.
COVID-19 Inzidenz-Widget für iOS innerhalb Deutschlands 🇩🇪
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 incidenceUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,last_update,cases,cases7_per_100k&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json` | |
const saveIncidenceLatLon = (location) => { | |
let fm = FileManager.iCloud() | |
let path = fm.joinPath(fm.documentsDirectory(), "covid19latlon.json") | |
fm.writeString(path, JSON.stringify(location)) | |
} | |
const getsavedIncidenceLatLon = () => { | |
let fm = FileManager.iCloud() | |
let path = fm.joinPath(fm.documentsDirectory(), "covid19latlon.json") | |
let data = fm.readString(path) | |
return JSON.parse(data) | |
} | |
let widget = await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentSmall() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
async function createWidget(items) { | |
let data, attr, header, label | |
const list = new ListWidget() | |
// 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("🦠 Neuinfektionen ".toUpperCase()) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(10) | |
label = list.addText("+"+data.features[0].attributes.value) | |
label.font = Font.mediumSystemFont(20) | |
label.centerAlignText() | |
const country = list.addText("Deutschland") | |
country.centerAlignText() | |
country.font = Font.mediumSystemFont(12) | |
country.textColor = Color.gray() | |
list.addSpacer() | |
// fetch new incidents | |
let location | |
if(args.widgetParameter) { | |
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat) | |
location = { | |
latitude: fixedCoordinates[0], | |
longitude: fixedCoordinates[1] | |
} | |
} else { | |
Location.setAccuracyToThreeKilometers() | |
try { | |
location = await Location.current() | |
console.log('get current lat/lon') | |
saveIncidenceLatLon(location) | |
} catch(e) { | |
console.log('using saved lat/lon') | |
location = getsavedIncidenceLatLon() | |
} | |
} | |
data = await new Request(incidenceUrl(location)).loadJSON() | |
if(!data || !data.features || !data.features.length) { | |
const errorList = new ListWidget() | |
errorList.addText("Keine Ergebnisse für den aktuellen Ort gefunden.") | |
return errorList | |
} | |
attr = data.features[0].attributes | |
const incidence = attr.cases7_per_100k.toFixed(1) | |
const cityName = attr.GEN | |
const cases =attr.cases | |
const lastUpdate = attr.last_update | |
header = list.addText("🦠 Inzidenz".toUpperCase()) | |
header.centerAlignText() | |
header.font = Font.mediumSystemFont(10) | |
label = list.addText(incidence) | |
label.centerAlignText() | |
label.font = Font.mediumSystemFont(24) | |
label2 = list.addText("("+cases+")") | |
label2.centerAlignText() | |
label2.font = Font.mediumSystemFont(12) | |
if(incidence >= 50) { | |
label.textColor = Color.red() | |
} else if(incidence >= 25) { | |
label.textColor = Color.orange() | |
} | |
const city = list.addText(cityName) | |
city.centerAlignText() | |
city.font = Font.mediumSystemFont(12) | |
city.textColor = Color.gray() | |
list.addSpacer() | |
label3 = list.addText ("letztes Update: "+lastUpdate.substr(0,10)) | |
label3.centerAlignText() | |
label3.font = Font.mediumSystemFont(6) | |
return list | |
} |
Was ist denn die Zahl in Klammern über Düsseldorf?
Das ist die Anzahl der aktuellen Fälle in Düsseldorf
Kann nicht sein, in meinem Landkreis sind aktuell 132 Fälle laut Landratsamt Seite und das Script zeigt mir 6521 an 🤷🏻♂️
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hallo, kenne mich nicht aus, aber kann mir von euch Profis jemand sagen wie ich erstellen kann, dass ich zum Beispiel 3 Landkreise sehe?