Skip to content

Instantly share code, notes, and snippets.

@basso314
Last active March 3, 2021 10:08
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save basso314/c8adb9c4248c9afb058c6dfce99c4437 to your computer and use it in GitHub Desktop.
Corona Lockdown
// 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()
}
@basso314
Copy link
Author

basso314 commented Nov 1, 2020

Hallo @caliban73,

ich habe die Zahlen aus dem Text ermittelt, getrennt und in das Array infectedArray gepackt (Zeile 93/94)
Dabei bedeutet dann:

  • infectedArray[0]: Gesamtzahl aller Infizierten (also auch der Immunen und der Gestorbenen)
  • infectedArray[1]: die Immunen
  • infectedArray[2]: Gesamtzahl aller in Quarantäne (aktuell Infizierte und Kontaktpersonen)
  • infectedArray[3]: Intensiv
  • infectedArray[4]: die Gestorbenen
    Daher habe ich dann auch die für mich wichtigen Werte (akut Infizierte und Kontaktpersonen in Quarantäne) anschließend ermittelt (Zeile 95/96) und diese werden dann ausgegeben (tx2 mit Überschrift tx1 und tx6 mit Überschrift tx5)

@caliban73
Copy link

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?

@basso314
Copy link
Author

basso314 commented Nov 1, 2020

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