Created
March 20, 2017 12:37
-
-
Save mikhailbot/28060909bbe276d537b328e36142f23b to your computer and use it in GitHub Desktop.
AWS Lambda Unfluff Test
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
'use strict'; | |
const unfluff = require('unfluff'); | |
const fetch = require('node-fetch'); | |
const TEST_URL = 'http://www.theverge.com/2017/3/17/14957460/the-legend-of-zelda-breath-of-the-wild-nintendo-switch-future-games'; | |
const extract = (html) => { | |
console.log('Got HTML'); | |
const results = unfluff(html); | |
console.log('Got unfluffed'); | |
return results; | |
} | |
const getHTML = (url) => { | |
return new Promise((resolve, reject) => { | |
fetch(TEST_URL) | |
.then(res => res.text()) | |
.then((body) => { | |
resolve(body); | |
}) | |
.catch((error) => { | |
console.log(error); | |
reject(error); | |
}) | |
}) | |
} | |
exports.handler = (event, context, callback) => { | |
console.log('unfluffing...') | |
getHTML(event).then(extract).then((result) => { | |
return callback(null, result); | |
}).catch((error) => { | |
return callback(error, null); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment