Skip to content

Instantly share code, notes, and snippets.

@Leibinger015
Created November 20, 2020 09:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leibinger015/b461a3f24bf25a952a8c88076f629b49 to your computer and use it in GitHub Desktop.
Save Leibinger015/b461a3f24bf25a952a8c88076f629b49 to your computer and use it in GitHub Desktop.
This is a Scriptable Widget Script for iOS. A World Air Quality Index Icon for your Homescreen.
// Das Skript habe ich auf Deutsch lokalisiert und es stammt aus der Quelle -> https://gist.github.com/SuperC1r0/a8aef6ec73108d03862aa96f278a72d7
//
//
//
// ***Air Quality Widget***
//
// Copyright (C) 2020 by SuperC1r0
//
// Permission to use, copy, modify, and/or distribute this software is hereby granted.
// However you have to respect the Terms of Service of the Air Quality Open Data Platform: https://aqicn.org/api/tos/
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
// IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
// OF THIS SOFTWARE.
//
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: magic;
//** Script for scriptable to get the current Air Polution of your city
//Thank you World Air Quality Index Project for gathering all the data!
function createWidget(keyword,aqi,date){
let widget = new ListWidget()
let title = widget.addText([keyword] + "'s Luftqualität")
title.font = Font.boldSystemFont(16)
title.textColor = Color.white()
title.centerAlignText()
title.minimumScaleFactor = 0.4
title.lineLimit = 2
widget.addSpacer()
let aqiTitle = widget.addText("AQI-Index")
aqiTitle.font = Font.regularSystemFont(10)
aqiTitle.textColor = Color.black()
aqiTitle.centerAlignText()
aqiTitle.minimumScaleFactor = 0.8
//Air Quality Levels
let aqiText = widget.addText(aqi)
aqiText.font = Font.boldSystemFont(30)
aqiText.centerAlignText()
aqiText.minimumScaleFactor = 1
if (aqi >= 300) {
aqiText.textColor = Color.white()
widget.backgroundColor = new Color("#7e0023")
let aqiText1 = widget.addText("GEFÄHRLICH:👎🛑😷")
aqiText1.font = Font.boldSystemFont(10)
aqiText1.textColor = Color.white()
aqiText1.centerAlignText()
aqiText1.minimumScaleFactor = 1
} else if (aqi >= 201) {
aqiText.textColor = Color.white()
widget.backgroundColor = new Color("#660099")
let aqiText1 = widget.addText("SEHR UNGESUND:✋🛑")
aqiText1.font = Font.boldSystemFont(9)
aqiText1.textColor = Color.white()
aqiText1.centerAlignText()
aqiText1.minimumScaleFactor = 0.7
} else if (aqi >= 151) {
aqiText.textColor = Color.white()
widget.backgroundColor = new Color("#cc0033")
let aqiText1 = widget.addText("UNGESUND:👎")
aqiText1.font = Font.boldSystemFont(10)
aqiText1.textColor = Color.white()
aqiText1.centerAlignText()
aqiText1.minimumScaleFactor = 0.8
} else if (aqi >= 101) {
aqiText.textColor = Color.white()
widget.backgroundColor = new Color("#ff9933")
let aqiText1 = widget.addText("BEDENKLICH:✋")
aqiText1.font = Font.boldSystemFont(10)
aqiText1.textColor = Color.black()
aqiText1.centerAlignText()
aqiText1.minimumScaleFactor = 0.7
} else if (aqi >= 51) {
aqiText.textColor = Color.white()
widget.backgroundColor = new Color("#66b266")
let aqiText1 = widget.addText("MÄSSIG:☝️")
aqiText1.font = Font.boldSystemFont(10)
aqiText1.textColor = Color.black()
aqiText1.centerAlignText()
aqiText1.minimumScaleFactor = 0.7
} else if (aqi >=0) {
aqiText.textColor = Color.white()
widget.backgroundColor = new Color("#006600")
let aqiText1 = widget.addText("GUT 👍")
aqiText1.font = Font.boldSystemFont(12)
aqiText1.textColor = Color.white()
aqiText1.centerAlignText()
}
else {
aqiText.textColor = Color.red()
widget.backgroundColor = Color.white()
}
widget.addSpacer()
//Last Update of Data
let dateText = widget.addText(date + " (Messzeit)")
dateText.font = Font.regularSystemFont(7)
dateText.centerAlignText()
dateText.minimumScaleFactor = 0.2
widget.addSpacer()
//Contribution to World Air Quality Project
let Text = widget.addText("A World Air Quality Project")
Text.font = Font.regularSystemFont(6)
Text.textColor = Color.black()
Text.centerAlignText()
Text.minimumScaleFactor = 0.2
return widget
}
//Get City from Air Quality Open Data Platform
async function getData(keyword) {
let req = new Request(`https://api.waqi.info/search/?keyword=${keyword}&token=19b71483eb9ddd3831a5e83312cd860fb00fa03d`)
req.method = "GET"
let response = await req.loadJSON()
if (Object.keys(response.data).length != 0) {
var result = '{"aqi" : "'+response.data[0].aqi+'", "date" : "'+response.data[0].time.stime+'"}'
} else {
var result = '{"aqi" : "N/A", "date" : "k. A."}'
}
return result
}
//Search Keyword in Air Quality Open Database
if (config.runsInApp) {
// Demo in-App visit https://aqicn.org/ for more cities
let keyword = "Berlin"
let data = await getData(keyword)
data = JSON.parse(data)
let widget = createWidget(keyword, data.aqi, data.date)
widget.presentSmall()
} else {
// Not in-App - use of fixed Parameter
let keyword = args.widgetParameter
let data = await getData(keyword)
data = JSON.parse(data)
let widget = createWidget(keyword, data.aqi, data.date)
Script.setWidget(widget)
}
Script.complete()
@Leibinger015
Copy link
Author

D64BEFF9-8926-48D6-A141-1EA8464BB180

Wie funktioniert dieses Luftqualitäts Widget?

••••••

Voraussetzung:

iOS 14 oder höher
Die aktuelle Scriptable App
••••••

Installation:

1.) Kopiere den Skript Code von oben

2.) Öffne die Scriptable App

3.) Klick auf das "+" Symbol oben rechts und füge das kopierte Skript ein

4.) Klick auf den Titel des Skripts ganz oben und vergebe einen Namen (z.B. Luftqualität)

5.) Speicher das Skript durch Klick auf "Done" oben links

6.) Gehe auf deinen iOS Homescreen und drücke irgendwo lang, um in den "wiggle mode" zu kommen (mit dem man auch die App Symbole anordnen kann)

7.) Drück das "+" Symbol oben links, blättere dann nach unten zu "Scriptable" (Liste ist alphabetisch), wähle die erste Widget Größe (small) und drück unten auf "Widget hinzugügen"

8.) Drück auf das Widget, um seine Einstellungen zu bearbeiten (optional lang drücken, wenn der Wiggle Modus schon beendet wurde)

9.) Wähle unter "Script" das oben erstellte aus (Luftqualität)

10.) Gib als "Parameter" deine STADT oder dein LAND ein, was dann im Homescreen Widget angezeigt werden soll.

91B2844E-D25D-4644-B907-B929FC64DEB7

@nawarumwas
Copy link

Wirklich cool.. 👍

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