-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel E. Fernández Pera
committed
Sep 27, 2019
0 parents
commit fd70b9a
Showing
13 changed files
with
881 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const request = require("request-promise-native"); | ||
|
||
handle(); | ||
|
||
// Task handler simulation | ||
async function handle(handlerInput) { | ||
// Make request | ||
const r = await request( | ||
prepareOptions("http://www.zaragoza.es/sede/servicio/informacion-polen") | ||
); | ||
|
||
// Parse response | ||
const json = JSON.parse(r.body); | ||
|
||
// Do stuff with response | ||
console.log("---------------------------"); | ||
console.log("| Raw body |"); | ||
console.log("---------------------------"); | ||
console.log(r.body); | ||
|
||
console.log("\n"); | ||
console.log("---------------------------"); | ||
console.log("| Parsed JSON |"); | ||
console.log("---------------------------"); | ||
console.log(json); | ||
|
||
console.log("\n"); | ||
console.log("-------------------------------------"); | ||
console.log("| Extracted values - General |"); | ||
console.log("-------------------------------------"); | ||
var talkResultGeneral = ""; | ||
const resultElements = json.result; | ||
resultElements.forEach(element => { | ||
console.log(element.title); | ||
console.log("\t Observaciones: " + element.observation); | ||
console.log("\t Observaciones (texto): " + JSON.stringify(element.observation)); | ||
console.log("\t Nivel: " + element.observation[0].value); | ||
|
||
talkResultGeneral += element.title + ":" + element.observation[0].value + ","; | ||
}); | ||
console.log("\nTalk result - General: \n\t" + talkResultGeneral); | ||
|
||
console.log("\n"); | ||
console.log("-------------------------------------"); | ||
console.log("| Extracted values - By level |"); | ||
console.log("-------------------------------------"); | ||
const level = "bajo"; | ||
var talkResultLevel = ""; | ||
const resultElementsLevel = json.result; | ||
resultElementsLevel.forEach(element => { | ||
if(element.observation[0].value === level) | ||
talkResultLevel += element.title + ","; | ||
}); | ||
if(talkResultLevel === "") | ||
talkResultLevel = "No hay medidas de nivel '" + level + "'"; | ||
console.log("\nTalk result - By level: \n\t" + talkResultLevel); | ||
} | ||
|
||
// Utility function | ||
function prepareOptions(url) { | ||
return { | ||
url: url, | ||
headers: { | ||
Accept: "application/json" | ||
}, | ||
resolveWithFullResponse: true | ||
}; | ||
} |
Oops, something went wrong.