Last active
December 15, 2016 17:47
-
-
Save niklbert/85183478ee96e7e8cca5734e806ef5dd to your computer and use it in GitHub Desktop.
fetchtweetsfromcloudant
This file contains hidden or 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
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