Skip to content

Instantly share code, notes, and snippets.

@joelalejandro
Last active October 17, 2016 06:04
Show Gist options
  • Save joelalejandro/27fd70209613ea35019c90e616f161a8 to your computer and use it in GitHub Desktop.
Save joelalejandro/27fd70209613ea35019c90e616f161a8 to your computer and use it in GitHub Desktop.
import Twit from 'twit';
import Config from 'config';
import Pace from 'pace';
import fs from 'fs';
// Sets the Twitter API configuration.
const T = new Twit(Config.get('twitter'));
const tweets = [];
// Defines language and sample size.
const tweetMax = Config.get('twoet.faux_detournement.sample_size');
const detournementContext = Config.get('twoet.detournement_context');
const progress = new Pace(tweetMax);
console.log(`Will fetch ${tweetMax} tweets with context: ${JSON.stringify(detournementContext)}`);
// Begins streaming.
const stream = T.stream('statuses/sample', detournementContext);
stream.on('tweet', (tweet) => {
progress.op();
tweets.push(tweet);
if (tweets.length === tweetMax) {
stream.stop();
// Once all tweets are collected, write them in a JSON file and leave.
fs.writeFileSync('config/faux_detournement_data.json', JSON.stringify(tweets));
process.exit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment