Skip to content

Instantly share code, notes, and snippets.

@mikhailbot
Created March 20, 2017 12:37
Show Gist options
  • Save mikhailbot/28060909bbe276d537b328e36142f23b to your computer and use it in GitHub Desktop.
Save mikhailbot/28060909bbe276d537b328e36142f23b to your computer and use it in GitHub Desktop.
AWS Lambda Unfluff Test
'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