Skip to content

Instantly share code, notes, and snippets.

@mstoeb2s
Last active January 29, 2021 09:51
Show Gist options
  • Save mstoeb2s/3c2c6c8c2811b88588c7866f4ab5d879 to your computer and use it in GitHub Desktop.
Save mstoeb2s/3c2c6c8c2811b88588c7866f4ab5d879 to your computer and use it in GitHub Desktop.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: green; icon-glyph: magic;
const apiUrl = "https://stadtplan.bonn.de/json?OD=4379"
const apiUrl2 = `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`;
var aktuell=7295
var gestern=0
var div=0
const widget = await createWidget();
if (!config.runsInWidget) {
await widget.presentSmall();
}
Script.setWidget(widget);
Script.complete();
async function createWidget() {
var url=new Request("https://stadtplan.bonn.de/json?OD=4379");
var bonnData = await url.loadString();
var data = JSON.parse(bonnData);
var fm = FileManager.iCloud()
var path = fm.documentsDirectory()
var data_b = fm.joinPath(path, "data.json")
if (!data || !data.features || !data.features.length) {
data=JSON.parse(fm.readString(data_b));
}
else {
try {
fm.writeString(data_b, bonnData)
} finally {
}
}
const data2 = await new Request(apiUrl2).loadJSON()
if(!data2 || !data2.features || !data2.features.length) {
const errorList2 = new ListWidget()
errorList.addText("Keine Ergebnisse für die Anfrage nach den Neuinfektionen.")
return errorList2
}
const attr = data2.features[0].attributes
const newCases = attr.value
if(aktuell!=newCases){
gestern=aktuell
aktuell=newCases
div=aktuell-gestern
}
var l = data.features.length;
var date_bonn=data.features[l-1].properties.datum;
var fallzahl_bonn=data.features[l-1].properties.sieben_tage_inzidenz;
var fallzahl_bonn_gestern=data.features[l-2].properties.sieben_tage_inzidenz;
var dif=fallzahl_bonn-fallzahl_bonn_gestern;
dif = dif.toFixed(2);
const list = new ListWidget()
if(Device.isUsingDarkAppearance()){
const gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [
new Color("111111"),
new Color("222222")
]
list.backgroundGradient = gradient
}
const header = list.addText("🦠 Corona".toUpperCase())
header.font = Font.mediumSystemFont(13)
header.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.addSpacer();
//if(div>0){
const label2 = list.addText("+" + newCases)
//}
//else {
// const label2 = list.addText(newCases +" " + "( -" + Math.abs(div) + ")")
//}
label2.font = Font.boldSystemFont(19)
label2.textColor = Color.green()
let text3 = list.addText("Neuinfektionen");
text3.font = Font.systemFont(15)
text3.textOpacity = 0.5;
text3.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.addSpacer();
var label
if(dif>0){
label= list.addText(fallzahl_bonn + ' ' + "(+" + dif + ")" );
}
else
{
label= list.addText(fallzahl_bonn + ' ' + "(" + dif + ")" );
}
label.font = Font.boldSystemFont(17);
label.textColor = Color.green();
if (fallzahl_bonn >= 50) {
label.textColor = Color.red()
} else if(fallzahl_bonn >= 35) {
label.textColor = Color.orange()
}
let text = list.addText("Inzidenz - Bonn");
text.font = Font.systemFont(14)
text.textOpacity = 0.5;
text.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.addSpacer();
let text2 = list.addText("Stand: " + date_bonn[8]+date_bonn[9]+"."+date_bonn[5]+date_bonn[6]+"."+date_bonn[0]+date_bonn[1]+date_bonn[2]+date_bonn[3]);
text2.font = Font.boldSystemFont(11)
text2.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.refreshAfterDate = new Date(Date.now() + 60*60*1000)
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment