Skip to content

Instantly share code, notes, and snippets.

@yagop yagop/emojis.js
Created Dec 25, 2016

Embed
What would you like to do?
Simple Twitter emoji streamer
const emojisStr = '๐Ÿ˜€๐Ÿ˜‚๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜˜๐Ÿ˜๐Ÿ˜œ๐Ÿ˜Ž๐Ÿค“๐Ÿ˜ถ๐Ÿ˜๐Ÿค—๐Ÿ˜๐Ÿ˜ก๐Ÿ˜Ÿ๐Ÿ˜ž๐Ÿ™„โ˜น๏ธ๐Ÿ˜”๐Ÿ˜ฎ๐Ÿ˜ด๐Ÿ’ค๐Ÿ’ฉ๐Ÿ˜ญ๐Ÿ˜ˆ๐Ÿ‘ฟ๐Ÿ‘Œ๐Ÿ‘ธ๐ŸŽ…๐Ÿ‘…๐Ÿ‘€๐Ÿ‘๐Ÿ’ช๐Ÿ‘ป๐Ÿค–๐Ÿ˜บ๐ŸŸ๐Ÿ ๐Ÿท๐ŸŒ๐Ÿผ๐Ÿบ๐Ÿฏ๐Ÿ…๐Ÿฆƒ๐Ÿ•๐Ÿ‡๐ŸŒพ๐ŸŽ๐Ÿ€๐Ÿพ๐ŸŒ๐ŸŒš๐ŸŒ๐ŸŒž๐ŸŒฆ๐Ÿ”ฅ๐Ÿ’ฅโ˜ƒ๏ธโœจโ„๏ธ๐Ÿ’ง๐Ÿ๐ŸŠ๐ŸŒ๐ŸŒฝ๐Ÿ”๐ŸŒฎโ˜•๏ธ๐Ÿงโšฝ๏ธ๐Ÿ๐ŸŽ–๐ŸŽน๐ŸŽฐ๐ŸŽฃ๐Ÿ“๐Ÿšต๐ŸŽฎ๐ŸŽฌ๐Ÿš—๐Ÿš“๐Ÿšจ๐Ÿš‹๐Ÿš ๐Ÿ›ฅ๐Ÿš€๐Ÿšข๐ŸŽ ๐Ÿšง๐Ÿšง๐Ÿšงโœˆ๏ธ๐Ÿฅ๐Ÿ“ฑโŒจ๐Ÿ’ป๐Ÿ“ ๐Ÿ“ž๐Ÿ”ฆ๐Ÿ’ด๐Ÿ’ธ๐Ÿ”ฎ๐Ÿ’Š๐Ÿ”ฌ๐Ÿ”ญ๐Ÿ“ซ๐Ÿ“ˆ๐Ÿ“‰๐Ÿ–‡โœ‚๏ธ๐Ÿ”’๐Ÿ”“๐Ÿ“’๐Ÿ’›โค๏ธ๐Ÿ’™๐Ÿ’”๐Ÿ’ž๐Ÿ’•๐Ÿ’๐Ÿ’˜๐Ÿšพโš ๏ธโ™ป๏ธ๐ŸŽต๐Ÿ’ฌ๐Ÿ•๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ‡ช๐Ÿ‡ธ๐Ÿ‡ต๐Ÿ‡น๐Ÿ‡ณ๐Ÿ‡บ๐Ÿ‡ณ๐Ÿ‡ท๐Ÿ‡ฌ๐Ÿ‡พ๐Ÿ‡ฌ๐Ÿ‡ฆ๐Ÿ‡ฎ๐Ÿ‡ธ๐Ÿ‡ฏ๐Ÿ‡ต';
const emojis = [...emojisStr]
.filter(emoji => emoji.length > 0)
.filter(emoji => emoji !== '\uFE0F');
module.exports = emojis;
const Twitter = require('twit');
const emojis = require('./emojis');
const twitter = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
const stream = twitter.stream('statuses/filter', {
track: emojis,
language: 'en'
});
const stats = {};
const tweetStreamer = tweet => {
const second = Math.floor(Date.now() / 1000);
if (stats[second] !== undefined) {
stats[second]++;
} else {
stats[second] = 1;
}
console.log(`ID: ${tweet.id}. Text: ${tweet.text}`)
}
stream.on('tweet', tweetStreamer);
process.on('SIGINT', () => {
console.log('Stats:');
Object.keys(stats).forEach(second => {
console.log(`[${second}]: ${stats[second]} tweets`);
});
process.exit();
});
{
"name": "twitter-stream-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"twit": "^2.2.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You canโ€™t perform that action at this time.