Skip to content

Instantly share code, notes, and snippets.

@mstoeb2s
Last active May 7, 2021 02:08
Show Gist options
  • Save mstoeb2s/a3e1c0732fcd82a27437b8dafb148f3d to your computer and use it in GitHub Desktop.
Save mstoeb2s/a3e1c0732fcd82a27437b8dafb148f3d to your computer and use it in GitHub Desktop.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: teal; icon-glyph: magic;
/*Wähle das Bundesland
0 Baden-Würtemberg
1 Bayern
2 Brandenburg
3 Berlin
4 Bremen
5 Hamburg
6 Hessen
7 Mecklenburg-Vorpommern
8 Niedersachsen
9 NRW
10 Rheinland-Pfalz
11 Saarland
12 Sachsen-Anhalt
13 Sachsen
14 Schleswig-Holstein
15 Thüringen
*/
//Bundesland
const BL = 9
//Quelle: ZEIT ONLINE
const apiUrl = "https://interactive.zeit.de/cronjobs/2020/corona/impfzahlenAutomatisch.json"
const widget = await createWidget();
if (!config.runsInWidget) {
await widget.presentSmall();
}
Script.setWidget(widget);
Script.complete();
async function createWidget() {
const data = await new Request(apiUrl).loadJSON();
const list = new ListWidget()
if(Device.isUsingDarkAppearance()){
const gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [
new Color("111111"),
new Color("222222")
]
list.backgroundGradient = gradient
}
const header = list.addText("💉 Impfungen".toUpperCase())
header.font = Font.mediumSystemFont(13)
header.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.addSpacer();
var impfGes=0;
for (var i=0; i<16; i++) {
impfGes=impfGes+data.bundeslaender[i].historical[0].value;
}
impfGes_dsp=impfGes.toLocaleString()
var impfGes_pro = impfGes/83020000*100;
impfGes_pro=impfGes_pro.toFixed(2);
label = list.addText("" + impfGes_dsp + " - " + impfGes_pro + "%");
label.font = Font.boldSystemFont(12.5);
label.textColor = Color.green();
var label = list.addText("Impfungen Gesamt");
label.font = Font.boldSystemFont(12);
label.textOpacity = 0.5;
label.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.addSpacer();
var einwohner
var BL_Text
if (BL==0) {einwohner=11070000 ; BL_Text="BW"}
if (BL==1) {einwohner=13080000 ; BL_Text="Bayern"}
if (BL==2) {einwohner=2520000 ; BL_Text="BB"}
if (BL==3) {einwohner=3769000 ; BL_Text="Berlin"}
if (BL==4) {einwohner=681000 ; BL_Text="Bremen"}
if (BL==5) {einwohner=1845000 ; BL_Text="Hamburg"}
if (BL==6) {einwohner=6266000 ; BL_Text="Hessen"}
if (BL==7) {einwohner=1610000 ; BL_Text="MV"}
if (BL==8) {einwohner=7982000 ; BL_Text="NI"}
if (BL==9) {einwohner=17947000 ; BL_Text="NRW"}
if (BL==10) {einwohner=4085000 ; BL_Text="RP"}
if (BL==11) {einwohner=987000 ; BL_Text="SL"}
if (BL==12) {einwohner=2208000 ; BL_Text="ST"}
if (BL==13) {einwohner=4078000 ; BL_Text="Sachsen"}
if (BL==14) {einwohner=2890000 ; BL_Text="SH"}
if (BL==15) {einwohner=2137000 ; BL_Text="TH"}
var impfBL=data.bundeslaender[BL].historical[0].value;
impfBL=impfBL.toLocaleString()
var impfBL_pro=data.bundeslaender[BL].historical[0].value/einwohner*100;
impfBL_pro=impfBL_pro.toFixed(2);
label = list.addText("" + impfBL + " - " + impfBL_pro + "%");
label.font = Font.boldSystemFont(12.5);
label.textColor = Color.green()
label = list.addText("Impfungen " + BL_Text );
label.font = Font.boldSystemFont(12);
label.textOpacity = 0.5;
label.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.addSpacer();
label = list.addText("Stand: ");
label.font = Font.boldSystemFont(10);
label.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
label = list.addText("" + data.timestamp);
label.font = Font.boldSystemFont(10);
label.textColor = Device.isUsingDarkAppearance() ? Color.white() : Color.black();
list.refreshAfterDate = new Date (Date.now() + 60*60*1000)
return list;
}
@QWERTZ000
Copy link

QWERTZ000 commented Jan 9, 2021

Hi mstoeb2s,

danke für das coole Widget. Ich habe es allerdings für meine Bedürfnisse etwas umgebaut. Ich habe vom scripten zwar absolut keine Ahnung, aber ich habe mir ein paar Zeilen umgebaut, von denen ich glaube zu wissen was sie bewirken. Folgendes ist dabei herausgekommen:
Bildschirmfoto 2021-01-09 um 10 34 04
Jetzt hätte ich aber noch gerne die Impfzahlen in dem gleichen grün, wie die Prozentangabe. Dabei soll DE und SH aber schwarz, bzw. weiss bleiben. Kannst du mir da vielleicht helfen? Besten Dank!

@mstoeb2s
Copy link
Author

mstoeb2s commented Jan 9, 2021

Hey! Das ist nicht ganz so einfach. Ich schaue mal, ob ich was finde.

@QWERTZ000
Copy link

Hey! Das ist nicht ganz so einfach. Ich schaue mal, ob ich was finde.

Das wäre ganz cool, ja. Aber bitte investiere nicht zu viel Zeit damit. So wichtig ist das nicht. Dachte nur, dass du vielleicht eine spontane Idee hast. Viel mehr würde mich ein Widget interessieren, welches die Todesfälle (Gesamt+Heute und Bundesland+Heute) des RKI anzeigt. Habe bisher keins gefunden. Und ich habe keinen Schimmer wie das mit den APIs funktioniert.

@Besenwiesler
Copy link

Das wäre ganz cool, ja. Aber bitte investiere nicht zu viel Zeit damit. So wichtig ist das nicht. Dachte nur, dass du vielleicht eine spontane Idee hast. Viel mehr würde mich ein Widget interessieren, welches die Todesfälle (Gesamt+Heute und Bundesland+Heute) des RKI anzeigt. Habe bisher keins gefunden. Und ich habe keinen Schimmer wie das mit den APIs funktioniert.

Für Anzeige der Todesfälle könntest du dieses Widget nehmen, für Todesfälle und Impfzahlen dieses hier.

@QWERTZ000
Copy link

QWERTZ000 commented Jan 11, 2021

Für Anzeige der Todesfälle könntest du dieses Widget nehmen, für Todesfälle und Impfzahlen dieses hier.

Danke für den Hinweis. Über die Widgets bin ich irgendwie noch gar nicht gestolpert.

@WorfvomDorf
Copy link

Ein gutes Widget.
Ich würde es gerne auch in einer Webseite nutzen.
Gibt es eine Möglichkeit es in eine HTML Seite zu integrieren ?
Kannst Du hier den Code für die Integration in eine Webseite veröffentlichen ?
Ich habe es versucht bin aber gescheitert......

@Krone76
Copy link

Krone76 commented Feb 3, 2021

Irgendwas scheint bei der Datenbankabfrage nicht mehr zu funktionieren. Bei mir ist der letzte Stand der 23.01.2021.

Hat vielleicht jemand eine Lösung für das Problem?

@mstoeb2s
Copy link
Author

mstoeb2s commented Feb 3, 2021

Hallo Krone76,
hast du die API angepasst?
const apiUrl = "https://interactive.zeit.de/cronjobs/2020/corona/impfzahlenAutomatisch.json"

Viele Grüße

@Krone76
Copy link

Krone76 commented Feb 3, 2021

Hallo mstoeb2s,

genau das war das Problem. Jetzt geht es wieder.

Vielen Dank für Deine schnelle Hilfe.

Gruß

Krone

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