Created
December 25, 2016 22:48
-
-
Save yagop/778ee035b72e6632dcb0333ef0bbd9c8 to your computer and use it in GitHub Desktop.
Simple Twitter emoji streamer
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 emojisStr = '๐๐๐ ๐๐๐๐๐๐๐ค๐ถ๐๐ค๐๐ก๐๐๐โน๏ธ๐๐ฎ๐ด๐ค๐ฉ๐ญ๐๐ฟ๐๐ธ๐ ๐ ๐๐๐ช๐ป๐ค๐บ๐๐ ๐ท๐๐ผ๐บ๐ฏ๐ ๐ฆ๐๐๐พ๐๐๐พ๐๐๐๐๐ฆ๐ฅ๐ฅโ๏ธโจโ๏ธ๐ง๐๐๐๐ฝ๐๐ฎโ๏ธ๐งโฝ๏ธ๐๐๐น๐ฐ๐ฃ๐๐ต๐ฎ๐ฌ๐๐๐จ๐๐ ๐ฅ๐๐ข๐ ๐ง๐ง๐งโ๏ธ๐ฅ๐ฑโจ๐ป๐ ๐๐ฆ๐ด๐ธ๐ฎ๐๐ฌ๐ญ๐ซ๐๐๐โ๏ธ๐๐๐๐โค๏ธ๐๐๐๐๐๐๐พโ ๏ธโป๏ธ๐ต๐ฌ๐๐ฌ๐ง๐บ๐ธ๐ช๐ธ๐ต๐น๐ณ๐บ๐ณ๐ท๐ฌ๐พ๐ฌ๐ฆ๐ฎ๐ธ๐ฏ๐ต'; | |
const emojis = [...emojisStr] | |
.filter(emoji => emoji.length > 0) | |
.filter(emoji => emoji !== '\uFE0F'); | |
module.exports = emojis; |
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 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(); | |
}); |
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
{ | |
"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