Skip to content

Instantly share code, notes, and snippets.

@klaus-schuster
Forked from rphl/incidence.js
Last active May 17, 2022 10:41
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save klaus-schuster/0537cd7f491a67ce61fe9064c4b4e932 to your computer and use it in GitHub Desktop.
Save klaus-schuster/0537cd7f491a67ce61fe9064c4b4e932 to your computer and use it in GitHub Desktop.
COVID-19 Inzidenz-Widget für iOS für HAMBURG (nutzt die Daten der HH-Website und nicht die des RKI)
// 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 Hamburg | https://www.hamburg.de/corona-zahlen
// 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(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("🦠 Hamburg")
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.hamburg.de/corona-zahlen'
let wbv = new WebView()
await wbv.loadURL(url)
//javasript to grab data from the website
let jsc = `
var arr = new Array()
var incr = document
.getElementsByClassName("cv_chart cv_color_seven")[0]
.getElementsByTagName("span")[0]
.innerText
arr.push(incr)
var sevend = document
.getElementsByClassName("cv_side_teaser")[0]
.getElementsByClassName("teaser-text c_chartheadline ")[0]
.getElementsByTagName("strong")[0]
.innerText
arr.push(sevend)
var updated = document
.getElementsByClassName("cv_side_teaser")[0]
.getElementsByClassName("teaser-text c_chartheadline ")[0]
.getElementsByTagName("strong")[1]
.innerText
.replace("(","")
.replace(")","")
arr.push(updated)
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[1]
let updated = val[2]
//Neuinfektionen
if (incr != null) {
let tx2 = widget.addText(incr)
tx2.leftAlignText()
tx2.font = vlFnt
}
let tx1 = widget.addText("Neuinfektionen")
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();
}
@basso314
Copy link

basso314 commented Oct 30, 2020

Hallo caliban73, hallo Klaus,

sorry, dass ich mich einmische, aber da die Daten von covid.9digits.de/lockdown auch für meinen Landkreis sehr aktuell und damit viel aktueller als die RKI-Daten sind, habe ich mich mal daran versucht. @klaus-schuster: ich habe deine Vorlage mal aufgenommen und angepasst.
In der Zeile 23 muss nur der Landkreisname eingetragen werden und in Zeile 59 die PLZ.
Die Anzahl der Personen in Quarantäne ist die aktuell zusätzlich in Quarantäne befindlichen Personen.

https://gist.github.com/basso314/c8adb9c4248c9afb058c6dfce99c4437

@klaus-schuster
Copy link
Author

super!

@caliban73
Copy link

Hallo caliban73, hallo Klaus,

sorry, dass ich mich einmische, aber da die Daten von covid.9digits.de/lockdown auch für meinen Landkreis sehr aktuell und damit viel aktueller als die RKI-Daten sind, habe ich mich mal daran versucht. @klaus-schuster: ich habe deine Vorlage mal aufgenommen und angepasst.
In der Zeile 23 muss nur der Landkreisname eingetragen werden und in Zeile 59 die PLZ.
Die Anzahl der Personen in Quarantäne ist die aktuell zusätzlich in Quarantäne befindlichen Personen.

https://gist.github.com/basso314/c8adb9c4248c9afb058c6dfce99c4437

Sehr gut. Danke.

@bondskin
Copy link

Hat noch jemand unter ios15 das Problem, dass das Widget nicht mehr funktioniert?

@basso314
Copy link

Ja, hier ebenso... wie ich auf reddit gelesen habe, liegt es daran, dass die WebView.GetHtml-Methode unter ios15 nicht mehr funktioniert.
Ich warte daher auf ein Update der Scriptable-App und benutze bis dahin ein Widget, das nur die API vom RKI abfragt, das funktioniert noch.

https://www.reddit.com/r/Scriptable/comments/pht7xy/webviewgethtml_doesnt_work_on_ios_15_beta/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment