Skip to content

Instantly share code, notes, and snippets.

@niklbert
Last active December 15, 2016 17:47
Show Gist options
  • Save niklbert/85183478ee96e7e8cca5734e806ef5dd to your computer and use it in GitHub Desktop.
Save niklbert/85183478ee96e7e8cca5734e806ef5dd to your computer and use it in GitHub Desktop.
fetchtweetsfromcloudant
const fs = require('fs');
const Cloudant = require('cloudant')({
url: 'https://9479bbf3-5af5-4af7-948d-7b335c9c4e04-bluemix.cloudant.com'
});
const db = Cloudant.db.use('starwarstweets');
var query = {
selector: {
lang: {
$eq: 'en'
}
},
fields: [
'payload',
'geo',
'place',
'coordinates',
'sentiment.score',
'tweet.created_at',
'location.place'
]
};
db.find(query, (err, docs) => {
if (err) return console.error('err', err);
const filename = `docs.${Date.now()}.json`;
docs.docs.forEach(d => {
fs.appendFileSync(filename, JSON.stringify(d));
});
console.log(`Wrote ${docs.docs.length} docs to ${filename}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment