Skip to content

Instantly share code, notes, and snippets.

@JLuetzen
Last active June 12, 2022 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLuetzen/056d96e2c796d21f0e78e888e0ad9f71 to your computer and use it in GitHub Desktop.
Save JLuetzen/056d96e2c796d21f0e78e888e0ad9f71 to your computer and use it in GitHub Desktop.
6 Webcams Sylt-Shuttle: Diese Seite gehört zur Homepage der WebcamWidgetsSylt: https://wwsylt.live. Ein iPhone Widget, das die 6 WebCams vom Blauen Autozug und vom Sylt Shuttle in Westerland und Niebüll auf dem Homescreen zeigt. Was genau zu tun ist, steht ganz unten.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: blue; icon-glyph: camera-retro;
// Script by Jens Luetzen: <kliffkieker67@gmail.com>
//
// NIB Cam1 https://www.autozug-sylt.de/webcam/niebuell/webcam_img_1.jpg
// NIB Cam2 https://www.autozug-sylt.de/webcam/niebuell/webcam_img_2.jpg
// NIB Cam3 https://www.autozug-sylt.de/webcam/niebuell/webcam_img_3.jpg
// WLD Cam1 https://www.autozug-sylt.de/webcam/westerland/61382/webcam_img_big.jpg
// funktioniert nicht mehr seit 2021.07: WLD Cam2 https://www.autozug-sylt.de/webcam/westerland/61380/webcam_img_big.jpg
// WLD CAM2 (ab 2021.08): https://paw14.de/WebCam_Voss_Papierhaus_Richtung_Sky/Voss2.jpg
// WLD Cam3 https://sylter-freizeit-team.de/webcamWE.jpg
// https://www.autozug-sylt.de/de/webcams/
//
// assigning parameters from scriptable callup
//
{
let param = args.widgetParameter;
//
// Initialization of variables
//
let campic; //number of cam being handed over to Widget
let errParam;
let url;
let widget;
let helpwidget;
let active_camlocation;
let active_camSubtitle;
const logoImg = await getImage('WWS-Logo.png');
//
// assignment of callup parameters to variables
//
if (param != null && param.length > 0) {
campic = param;
errParam = "Parameter received. ";
} else {
campic = 1;
errParam = "No Parameter received";
}
//
// creating JSON for Cam location, preview jpg URL and livestream URL
//
let myWebCams = {
"camLocation" : [
"Autoverladung Niebüll" ,
"Autoverladung WESTERLAND"] ,
"camSubtitle" : [
"Cam 1" ,
"Cam 2" ,
"Cam 3"] ,
"imgURL" : [
"https://www.autozug-sylt.de/webcam/niebuell/webcam_img_1.jpg" ,
"https://www.autozug-sylt.de/webcam/niebuell/webcam_img_2.jpg" ,
"https://www.autozug-sylt.de/webcam/niebuell/webcam_img_3.jpg" ,
"https://www.autozug-sylt.de/webcam/westerland/61382/webcam_img_big.jpg" ,
// "https://www.autozug-sylt.de/webcam/westerland/61380/webcam_img_big.jpg" ,
"https://paw14.de/WebCam_Voss_Papierhaus_Richtung_Sky/Voss2.jpg" ,
"https://sylter-freizeit-team.de/webcamWE.jpg"]
};
//
// Creating value for date and time
//
let actualdate = new Date();
let lastrefresh = new DateFormatter();
lastrefresh.useShortDateStyle();
lastrefresh.useShortTimeStyle();
timestamp = lastrefresh.string(actualdate);
//
// Main: display preview pics with information or helpwidget, if parameters are missing
//
switch (errParam) {
case "Parameter received. ":
if (campic <= 3) {
active_camlocation = myWebCams.camLocation[0];
active_camSubtitle = myWebCams.camSubtitle[campic-1] + " - " + timestamp;
} else {
active_camlocation = myWebCams.camLocation[1];
active_camSubtitle = myWebCams.camSubtitle[campic-4] + " - " + timestamp;
}
url = myWebCams.imgURL[campic-1];
let imgReq = await new Request(url);
let img = await imgReq.loadImage();
let widget = createWidget(img,active_camlocation,active_camSubtitle,url,logoImg);
if (!config.runsInWidget) {
await widget.presentLarge();
} else {
await Script.setWidget(widget);
}
break;
case "No Parameter received":
let helpwidget = createHelpWidget();
if (!config.runsInWidget) {
await helpwidget.presentLarge();
} else {
await Script.setWidget(helpwidget);
}
break;
}
Script.complete()
}
//
// end Main
//
//
// Here come the functions
//
//
// Creating Widget with parameters img, camLocation cLoc and camSubtitle cSub
//
function createWidget(prv_img,prv_Loc,prv_Subt,prv_URL,prvlogoImg) {
const widget = new ListWidget();
sourceURL = "https://wwsylt.live";
widget.backgroundColor = Color.black();
widget.url = prv_URL;
widget.backgroundImage = prv_img;
widget.setPadding(3,15,15,3);
const logoStack = widget.addStack();
logoStack.addSpacer();
const logoImageStack = logoStack.addStack();
logoImageStack.addSpacer();
const wimg = logoImageStack.addImage(prvlogoImg);
wimg.imageSize = new Size(80, 80);
wimg.rightAlignImage();
widget.addStack;
widget.addSpacer();
const titleText = widget.addText(prv_Loc);
titleText.font = Font.boldSystemFont(12);
titleText.textColor = Color.white();
titleText.shadowRadius = 3;
titleText.shadowColor = Color.black();
widget.addSpacer(2);
const subtitleText = widget.addText(prv_Subt);
subtitleText.font = Font.systemFont(8);
subtitleText.textColor = Color.white();
subtitleText.textOpacity = 0.8;
subtitleText.shadowRadius = 3;
subtitleText.shadowColor = Color.black();
const sourceURLText = widget.addText(sourceURL);
sourceURLText.font = Font.systemFont(8);
sourceURLText.textColor = Color.white();
sourceURLText.textOpacity = 0.8;
sourceURLText.shadowRadius = 3;
sourceURLText.shadowColor = Color.black();
return widget;
}
//
// Creating HELP-Widget without parameters
//
function createHelpWidget() {
const helpwidget = new ListWidget;
helpwidget.backgroundColor = Color.blue();
const titleText = helpwidget.addText("To Do's to configure the Widget");
titleText.leftAlignText();
titleText.font = Font.boldSystemFont(12);
titleText.textColor = Color.white();
myText = addLine(helpwidget,"===============================");
helpwidget.addSpacer(1);
myText = addLine(helpwidget,"1. Widget lange drücken für den Config Mode");
helpwidget.addSpacer(1);
myText = addLine(helpwidget,"2. Option Scripts: dieses Script wählen");
helpwidget.addSpacer(1);
myText = addLine(helpwidget,"3. Option When interacting: 'Open URL'");
helpwidget.addSpacer(1);
myText = addLine(helpwidget,"4. Option Parameter: Zahl zwischen 1 und 6");
helpwidget.addSpacer(1);
myText = addLine(helpwidget,"5. Fertig mit einzelnem Widget, wiederholen für restl. 5 Cams");
helpwidget.addSpacer(1);
myText = addLine(helpwidget,"6. Widges aufeinander ziehen für scrollbaren Smart Stack");
return helpwidget;
}
//
// Adds single line to the widget, parameter: text to be displayed
//
function addLine(prvHW,prvTXT) {
var TextLine = prvHW.addText(prvTXT);
TextLine.leftAlignText();
TextLine.font = Font.boldSystemFont(10);
TextLine.textColor = Color.white();
}
// get images from local filestore or download them once
async function getImage(image) {
let fm = FileManager.local();
let dir = fm.documentsDirectory();
let path = fm.joinPath(dir, image);
if (fm.fileExists(path)) {
return fm.readImage(path);
} else {
// download once
let logoUrl;
switch (image) {
case 'WWS-Logo.png':
logoUrl = "https://wwsylt.live/images/WWS_Logo.png";
console.log("set URL: " + logoUrl);
break
default:
console.log(`Sorry, couldn't find ${image}.`);
}
console.log("passing URL: " + logoUrl);
let iconImage = await loadImage(logoUrl);
fm.writeImage(path, iconImage);
return iconImage;
}
}
// helper function to download an image from a given url
async function loadImage(prvlogoUrl) {
console.log(`passed URL: ${prvlogoUrl}.`);
const req = new Request(prvlogoUrl);
return await req.loadImage();
}
@JLuetzen
Copy link
Author

JLuetzen commented Aug 21, 2021

2021-08-20
Seit Juli 2021 geht in Westerland die Webcam2 nicht mehr. Heute habe ich den Link ausgetauscht und jetzt zeigt das Widget die Cam vom Papierhaus Voss.
Zum Aktualisieren einfach das komplette Script von hier wieder auf das iPhone kopieren, wie in der Anleitung beschrieben. Mehr muss man nicht machen. Das Widget zeigt automatisch die neue Cam.

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