Last active
January 19, 2021 13:23
-
-
Save klaus-schuster/0cff4f6c674a89b79a8e024bd2f459dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: deep-blue; icon-glyph: grimace; | |
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// Corona Zahlen Lahn-Dill | https://www.lahn-dill-kreis.de/buergerservice/gesundheitsamt/hygiene-infektion/lahn-dill-kreisdecoronavirus/ | |
// Credits: | |
// kevinkub https://gist.github.com/kevinkub/46caebfebc7e26be63403a7f0587f664 | |
// rphl https://gist.github.com/rphl/0491c5f9cb345bf831248732374c4ef5 | |
// eqsOne https://talk.automators.fm/t/widget-examples/7994/379 | |
let widget = new ListWidget() | |
widget.setPadding(16, 16, 16, 16) | |
const spc = 3 | |
let hourNow = new Date().getHours() | |
//Define nighttime (19h - 7h) for styling changes | |
var nightTime = (hourNow >= 19 || hourNow < 7) | |
//Title text | |
let titleTxt = widget.addText("🦠 Lahn-Dill") | |
titleTxt.font= Font.boldSystemFont(17) | |
titleTxt.leftAlignText() | |
widget.addSpacer(spc*2) | |
//Value text | |
let vlFnt = Font.semiboldSystemFont(20) | |
//Subtitle text | |
let ptFnt = Font.systemFont(8) | |
let ptCol | |
//Backgrund- & text colors | |
if (nightTime) { | |
//titleTxt.textColor = Color.lightGray() | |
//ptCol = Color.gray() | |
const gradient = new LinearGradient() | |
gradient.locations = [0, 1] | |
gradient.colors = [ | |
new Color("192331"), | |
new Color("222222") | |
] | |
//widget.backgroundGradient = gradient | |
} | |
else { | |
//titleTxt.textColor = Color.darkGray() | |
//ptCol = Color.darkGray() | |
} | |
await loadSite() | |
if (!config.runsInWidget) widget.presentSmall() | |
Script.setWidget(widget) | |
Script.complete() | |
async function loadSite() { | |
let url='https://www.lahn-dill-kreis.de/buergerservice/gesundheitsamt/hygiene-infektion/lahn-dill-kreisdecoronavirus/' | |
let wbv = new WebView() | |
await wbv.loadURL(url) | |
//javasript to grab data from the website | |
let jsc = ` | |
var arr = new Array() | |
try {var sevend = document.body.innerText | |
.match(/Die 7-Tage-Inzidenz für den Lahn-Dill-Kreis beträgt\\s\\d{1,},?\\d{1,2}?(?=\.)/gm).toString().replace("Die 7-Tage-Inzidenz für den Lahn-Dill-Kreis beträgt ","")} | |
catch {var sevend = "?"} | |
console.log(sevend) | |
arr.push(sevend) | |
try {var updated = document.body.innerText | |
.match(/Stand:.{20}/s).toString() | |
.match(/\\d{1,2}\.\\d{1,2}\.\\d{2,4}/s).toString()} | |
catch {var updated = "?"} | |
console.log(updated) | |
arr.push(updated) | |
try {var aktiv = document.body.innerText | |
.match(/\\d{1,}.(?=aktive Corona-Fälle)/gm).toString()} | |
catch {var aktiv = "?"} | |
console.log(aktiv) | |
arr.push(aktiv) | |
try {var betreut = document.body.innerText | |
.match(/sowie.*.(?=Kontaktpersonen)/gm).toString() | |
.replace("sowie ","")} | |
catch {var betreut = "?"} | |
console.log(betreut) | |
arr.push(betreut) | |
JSON.stringify(arr) | |
` | |
//Run the javascript | |
let jsn = await wbv.evaluateJavaScript(jsc) | |
//Parse the grabbed values into a variable | |
let val = JSON.parse(jsn) | |
//Assign the parts to single variables | |
//let incr = val[0] | |
let sevend = val[0] | |
let updated = val[1] | |
let aktiv = val[2] | |
let betreut= val[3] | |
//Aktiv | |
if (aktiv != null) { | |
let tx2 = widget.addText(aktiv + " / " + betreut) | |
tx2.leftAlignText() | |
tx2.font = vlFnt | |
} | |
let tx1 = widget.addText("Aktive / Betreute Fälle") | |
tx1.textColor = ptCol | |
tx1.font= ptFnt | |
tx1.leftAlignText() | |
widget.addSpacer(spc) | |
//7 Tage Inz. | |
if (sevend != null) { | |
let tx4 = widget.addText(sevend) | |
tx4.leftAlignText() | |
tx4.font = vlFnt | |
if (parseFloat(sevend) >= 50) { | |
tx4.textColor = Color.red() | |
} else if (parseFloat(sevend) >= 35) { | |
tx4.textColor = Color.orange() | |
} else { | |
tx4.textColor = Color.green() | |
} | |
} | |
let tx3 = widget.addText("7-Tage Inzidenz") | |
tx3.textColor = ptCol | |
tx3.font= ptFnt | |
tx3.leftAlignText() | |
widget.addSpacer(spc*4) | |
// UPDATED | |
let today = new Date() | |
let updated_date = new Date() | |
updated_date.setYear(parseInt(updated.substr(6, 4))) | |
updated_date.setMonth(parseInt(updated.substr(3, 2))-1) | |
updated_date.setDate(parseInt(updated.substr(0, 2))) | |
let tx5 = widget.addText(updated) | |
tx5.font = Font.systemFont(14) | |
tx5.rightAlignText() | |
if (sameDate(today,updated_date)) { | |
tx5.textColor = Color.green() | |
} else { | |
tx5.textColor = Color.red() | |
} | |
let tx6 = widget.addText("Datenstand Website") | |
tx6.textColor = ptCol | |
tx6.font= ptFnt | |
tx6.rightAlignText() | |
} | |
function sameDate(date1, date2) { | |
return date1.getDate() == date2.getDate() && | |
date1.getMonth() == date2.getMonth() && | |
date1.getFullYear() == date2.getFullYear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hallo,
da Sie das hier so wunderbar gelöst haben, hätte ich auch mal eine Frage bzw. ein Anliegen.
Leider kann ich selbst nicht scripten, jedoch würde mich interessieren, ob man auch die Daten aus folgender Quelle ziehen kann:
https://geoportal.kreis-warendorf.de/geoportal/geo-online/?layerIDs=4,192,104,329,330&visibility=true,true,true,true,true&transparency=0,60,0,0,0¢er=428292,5747700&zoomlevel=1
Egal welches Script ich benutze, wird mir natürlich nur die Zahl des Kreises Warendorf angezeigt, da die Daten des RKI nicht die Gemeinden zeigen. Ich hätte aber gern den 7-Tage-Inzidenzwert der Stadt Ahlen.
Gäbe es die Möglichkeit, die Werte dort her zu ziehen?
Am liebsten hätte ich gern ein Widget, welches mir die Neuinfektionen in Deutschland zeigt, den 7-Tage-Inzidenzwert von Ahlen mit Neuinfizierten und wenn möglich die Gesamtzahl an Impfungen in DE.
Würde mich über eine Antwort freuen.
Besten Dank vorab!