-
-
Save wolfposd/596cacf6958a5e2bfbbe2c7ff295a467 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)
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. | |
// This script was downloaded using ScriptDude. | |
// Do not remove these lines, if you want to benefit from automatic updates. | |
// source: https://gist.github.com/wolfposd/596cacf6958a5e2bfbbe2c7ff295a467/raw/incidence.js; docs: https://gist.github.com/wolfposd/596cacf6958a5e2bfbbe2c7ff295a467/; | |
// Corona Zahlen Hamburg | https://www.hamburg.de/corona-zahlen | |
// Credits: | |
// klaus-schuster: https://gist.github.com/klaus-schuster/0537cd7f491a67ce61fe9064c4b4e932 | |
// 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 newInfect = document.querySelectorAll('[data-label]')[4].innerHTML | |
arr.push(newInfect) | |
var sevend = document.querySelectorAll('[data-label]')[1].innerHTML | |
arr.push(sevend) | |
var dateCrawl = document.querySelectorAll('[data-label]')[2].innerHTML | |
arr.push(dateCrawl) | |
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 7-Tage") | |
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