From 3ee1f05a114905dc7db74051a87ade8821774e88 Mon Sep 17 00:00:00 2001 From: CARLOS RAUL PEREZ MORENO Date: Sat, 13 Oct 2018 12:52:18 +0200 Subject: [PATCH] feat(): choose if you want to show UI or not and add actions with the text at the end of the request. --- BarrioPilarMetroTimming.js | 6 +++- PuertaArgandaMetroTimming.js | 6 +++- libs/TransportTiming.js | 65 +++++++++++++++++++++--------------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/BarrioPilarMetroTimming.js b/BarrioPilarMetroTimming.js index 888d178..273cb95 100644 --- a/BarrioPilarMetroTimming.js +++ b/BarrioPilarMetroTimming.js @@ -10,4 +10,8 @@ let fmLocal = FileManager.local(); eval(fmLocal.readString(libraryPath)); -metroTiming("902"); \ No newline at end of file +let completionCallback = function(text){ + Speech.speak(text) +} + +metroTiming("902", false, completionCallback); \ No newline at end of file diff --git a/PuertaArgandaMetroTimming.js b/PuertaArgandaMetroTimming.js index f83a6a4..d3d4f54 100644 --- a/PuertaArgandaMetroTimming.js +++ b/PuertaArgandaMetroTimming.js @@ -10,4 +10,8 @@ let fmLocal = FileManager.local(); eval(fmLocal.readString(libraryPath)); -metroTiming("922"); \ No newline at end of file +let completionCallback = function(text){ + Speech.speak(text) +} + +metroTiming("922", false, completionCallback); \ No newline at end of file diff --git a/libs/TransportTiming.js b/libs/TransportTiming.js index 40440ff..b73fc6e 100644 --- a/libs/TransportTiming.js +++ b/libs/TransportTiming.js @@ -1,35 +1,46 @@ // Variables used by Scriptable. // These must be at the very top of the file. Do not edit. // icon-color: red; icon-glyph: bus-alt; share-sheet-inputs: plain-text; -var metroTiming = function (station) { +var metroTiming = async function (station, presentUI, callback) { + let req = new Request("https://serviciosapp.metromadrid.es/servicios/rest/teleindicadores/" + station + "?") - let promiseResponse = req.loadJSON() - promiseResponse.then(json => { - - let array = json["Vtelindicadores"] - let table = new UITable() - - for (item of array) { - - let row = new UITableRow() - let title = item["nombreest"] + " sentido " + item["sentido"] - let subtitle = "" - if (item["proximo"]["@nil"] == "true") { - subtitle = "1 -> " + item["siguiente"] + " minutos" - } else if (item["siguiente"]["@nil"] == "true") { - subtitle = "1 -> " + item["proximo"] + " minutos" - } else { - subtitle = "1 -> " + item["proximo"] + " minutos, 2 -> " + item["siguiente"] + " minutos" - } - - let titleCell = row.addText(title, subtitle) - titleCell.widthWeight = 80 - - row.height = 60 - row.cellSpacing = 10 - table.addRow(row) + let json = await req.loadJSON() + + let array = json["Vtelindicadores"] + let table = new UITable() + let speaksText = "" + + for (item of array) { + + let row = new UITableRow() + let title = item["nombreest"] + " sentido " + item["sentido"] + speaksText = speaksText + "Tren desde " + item["nombreest"] + " sentido " + item["sentido"] + ". " + let subtitle = "" + if (item["proximo"]["@nil"] == "true") { + subtitle = "1 -> " + item["siguiente"] + " minutos" + speaksText = speaksText + "El primero pasarĂ¡ en " + item["siguiente"] + " minutos. " + } else if (item["siguiente"]["@nil"] == "true") { + subtitle = "1 -> " + item["proximo"] + " minutos" + speaksText = speaksText + "El primero pasarĂ¡ en " + item["proximo"] + " minutos. " + } else { + subtitle = "1 -> " + item["proximo"] + " minutos, 2 -> " + item["siguiente"] + " minutos" + speaksText = speaksText + "El primero pasarĂ¡ en " + item["proximo"] + " minutos y el segundo en " + item["siguiente"] + " minutos. " } + + let titleCell = row.addText(title, subtitle) + titleCell.widthWeight = 80 + + row.height = 60 + row.cellSpacing = 10 + table.addRow(row) + + } + + if (presentUI) { QuickLook.present(table) - }) + } + + callback(speaksText) + };