-
-
Save allesmatze/29647da84394e87f5ef045dccda845c1 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 apiUrl = (location) => `https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k,cases&geometry=${location.longitude.toFixed(3)}%2C${location.latitude.toFixed(3)}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json` | |
let widget = await createWidget() | |
if (!config.runsInWidget) { | |
await widget.presentSmall() | |
} | |
Script.setWidget(widget) | |
Script.complete() | |
async function createWidget(items) { | |
let location | |
if(args.widgetParameter) { | |
const fixedCoordinates = args.widgetParameter.split(",").map(parseFloat) | |
location = { | |
latitude: fixedCoordinates[0], | |
longitude: fixedCoordinates[1] | |
} | |
} else { | |
Location.setAccuracyToThreeKilometers() | |
location = await Location.current() | |
} | |
const data = await new Request(apiUrl(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 | |
} | |
const attr = data.features[0].attributes | |
const incidence = attr.cases7_per_100k.toFixed(1) | |
const cityName = attr.GEN | |
const totalCases = attr.cases | |
const list = new ListWidget() | |
const gradient = new LinearGradient() | |
gradient.locations = [0, 1] | |
if(Device.isUsingDarkAppearance()){ | |
gradient.colors = [ | |
new Color("111111"), | |
new Color("222222") | |
] | |
} else { | |
gradient.colors = [ | |
new Color("DDDDDD"), | |
new Color("FFFFFF") | |
] | |
} | |
list.backgroundGradient = gradient | |
const header = list.addText("🦠 Inzidenz".toUpperCase()) | |
header.font = Font.mediumSystemFont(13) | |
list.addSpacer() | |
const incidenceLabel = list.addText(incidence+"") | |
incidenceLabel.font = Font.boldSystemFont(24) | |
incidenceLabel.textColor = Color.green() | |
if(incidence >= 50) { | |
incidenceLabel.textColor = Color.red() | |
} else if(incidence >= 35) { | |
incidenceLabel.textColor = Color.orange() | |
} | |
const totalCasesLabel = list.addText(totalCases+"") | |
totalCasesLabel.font = Font.boldSystemFont(16) | |
list.addText(cityName) | |
return list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forked script.
Changes: