twitter-stream-cli 0.2.1
Twitter streams. This is a cli tool and also a npm lib.
- Track multiples words
- Output results in several formats
- Send results to a
Firebase Database
- Instructions to run severals instances with
pm2
Install
This tool requires node.js. I suggest you to use nvm
npm install twitter-stream-cli -g
Configure .env file
- Create an
.env
file:
touch .env# or use wget wget https://raw.githubusercontent.com/saitodisse/twitter-stream-cli/master/.env-example -O .env
- Create an app on https://apps.twitter.com/ and put keys on
.env
file:
# Twitter API keys: https://apps.twitter.com CONSUMER_KEY=__XXX__CONSUMER_SECRET=__XXX__TOKEN=__XXX__TOKEN_SECRET=__XXX__ # [optional] Firebase: https://console.firebase.google.com FIREBASE_APIKEY=__XXX__FIREBASE_DATABASEURL=__XXX__
Run as cli tool
# will track banana twitter-stream-cli banana # will track banana tweets OR chocolate tweets twitter-stream-cli banana chocolate # will track banana and chocolate in the same tweet message twitter-stream-cli "banana chocolate"
Format output
twitter-stream-cli banana --short #output: @user (lang): 80 char tweet text twitter-stream-cli banana --long #output: @user (lang, id, date): full tweet text twitter-stream-cli banana --json #output: full json result twitter-stream-cli banana --json-formatted #output: full formatted json result twitter-stream-cli banana --json-inspect #output: inspect json result with colors
Send json result to Firebase
-
Edit
.env
file. Replace__XXX__
onFIREBASE_URL=https://__XXX__.firebaseio.com
: -
Send results
twitter-stream-cli banana --send
Run multiples instances with pm2
We can easily run multiples instances of this tool with pm2
.
Install pm2
npm i pm2 -g
Create configuration files
Create app.json
mkdir pm2touch pm2/app.json
Edit app.json
:
"apps" : "name" : "banana" "script" : "twitter-stream-cli" "args" : "banana" "log_date_format" : "YYYY-MM-DD HH:mm:ss Z" "autorestart" : true "exec_mode" : "fork" "max_memory_restart": "100M" "name" : "chocolate" "script" : "twitter-stream-cli" "args" : "chocolate" "log_date_format" : "YYYY-MM-DD HH:mm:ss Z" "autorestart" : true "exec_mode" : "fork" "max_memory_restart": "100M"
Now you can start watching banana & cholocate in separeted instances. This will send to differents firebase URLs.
# edit pm2/app.json with your tracking terms pm2 start pm2/app.json
Check is everything is running ok:
# you can see logs and monitore pm2 listpm2 monit # delete and stop all instances pm2 delete all
Use as lib
Install
npm install twitter-stream-cli --save
Use
// ES5var TwiterStream ;var twiterStream = track: 'banana';return twiterStream;
// ES6;const twiterStream = track: 'banana';return twiterStream;
Test and run locally
git clone git@github.com:saitodisse/twitter-stream-cli.gitcd twitter-stream-clinpm installnpm testnode ./bin/twitter-stream-cli.js -h # all available tasks gulp help