Last active
March 3, 2021 10:08
-
-
Save basso314/c8adb9c4248c9afb058c6dfce99c4437 to your computer and use it in GitHub Desktop.
Corona Lockdown
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
// 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 Lockdown Zahlen | https://covid.9digits.de/lockdown/26655 | |
// 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 | |
// klaus schuster https://gist.githubusercontent.com/klaus-schuster/0537cd7f491a67ce61fe9064c4b4e932 | |
let widget = new ListWidget() | |
widget.setPadding(8, 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("🦠 Ammerland") | |
titleTxt.font= Font.boldSystemFont(14) | |
titleTxt.leftAlignText() | |
widget.addSpacer(spc*2) | |
//Value text | |
let vlFnt = Font.semiboldSystemFont(20) | |
//Subtitle text | |
let ptFnt = Font.systemFont(12) | |
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://covid.9digits.de/lockdown/26655' | |
let wbv = new WebView() | |
await wbv.loadURL(url) | |
//javasript to grab data from the website | |
let jsc = ` | |
var arr = new Array() | |
var info = document | |
.getElementsByClassName("lead")[2] | |
.innerText | |
arr.push(info) | |
var sevend = document | |
.getElementsByClassName("cover-heading")[0] | |
.innerText | |
arr.push(sevend) | |
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 info = val[0] | |
let sevend = val[1] | |
//Info-Text | |
let infected = info.replace("Infected: ","").replace("Immune: ","").replace("Quarantine: ","").replace("Intensive: ","").replace("Deaths: ","") | |
let infectedArray = infected.split(" - ") | |
let acuteInfected = parseFloat(infectedArray[0]) - parseFloat(infectedArray[1]) - parseFloat(infectedArray[4]) | |
let acuteQuarantine = parseFloat(infectedArray[2]) - acuteInfected | |
let tx2 = widget.addText(acuteInfected.toString()) | |
tx2.leftAlignText() | |
tx2.font = vlFnt | |
let tx1 = widget.addText("Aktuell Infiziert") | |
tx1.textColor = ptCol | |
tx1.font= ptFnt | |
tx1.leftAlignText() | |
widget.addSpacer(spc) | |
let tx6 = widget.addText(acuteQuarantine.toString()) | |
tx6.leftAlignText() | |
tx6.font = vlFnt | |
let tx5 = widget.addText("In Quarantäne") | |
tx5.textColor = ptCol | |
tx5.font= ptFnt | |
tx5.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() | |
} |
Kann man leider nicht, den Wert wollte ich auch haben.
Aber die Seite beinhaltet leider kein Aktualisierungsdatum, das wäre dort noch mal eine Verbesserung wert.
Man könnte höchstens über eine andere Webseite zusätzlich noch gehen (die Daten kommen ja vom CEDIM Institut Karlsruhe) und versuchen, dort an das entsprechende Aktualisierungsdatum heranzukommen (http://www.risklayer-explorer.com/event/100/detail)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hab vielen Dank für deine Antwort. Habe es mir es eine Weile angesehen und tatsächlich hinbekommen. Genau so wie du es hier beschreibst. Super vielen Dank.
Kann man auch noch den Stand, also die Aktualisierung abrufen einblenden? Weißt Du das?