-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMostWantedAudiWidget.js
56 lines (44 loc) · 1.54 KB
/
MostWantedAudiWidget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: magic;
//@ts-check
/**
* Create the widget
* @param {{widgetParameter: string, debug: string}} config widget configuration
*/
async function createWidget(config) {
const widget = new ListWidget()
const log = config.debug ? console.log.bind(console) : function () {};
log(JSON.stringify(config, null, 2))
let carline = 'etron' // Default
let param = config.widgetParameter
if (param != null && param.length > 0) {
carline = param
}
try {
// URL
const mwaRequest = new Request("https://mwa-api.apps.emea.vwapps.io/v2/mwa/carline/" + carline + "/de-DE");
const mwaResponse = await mwaRequest.loadJSON();
widget.setPadding(0, 0, 0, 0);
widget.backgroundColor = new Color("#000000")
const req = new Request(mwaResponse.renderPicture);
const image = await req.loadImage();
widget.addImage(image);
widget.url='https://mwa-fe.apps.emea.vwapps.io/?carline='+carline
} catch (error) {
log(JSON.stringify(error))
widget.addSpacer(4)
widget.backgroundColor = new Color("#ff0000")
widget.setPadding(10, 10, 10, 10)
widget.addText("no data found for " + carline)
let currentTime = new Date().toLocaleTimeString('de-DE', {
hour: "numeric",
minute: "numeric"
})
widget.addText(currentTime)
}
return widget
}
module.exports = {
createWidget
}