dstwitter is a module for simplifying data analysis and manipulation of twitter tweets and users. It integrates into dstools by adding functions to the dstools collection object. See the dstools documentation for some more information about the dstools module.
An important feature is its ability to break single requests with many required items into many API calls and when reached twitter API quota, wait for 15 minutes until the API is open again. For example, if you would like to search for 10,000 tweets about javascript, a single API call will not do. The twitter API limits each request to 100 tweets and there can only be 180 API calls in a 15 minute window. This package handles paging and waits when reached the 15 minute window quota.
You will need access token key, access token secret, consumer key and consumer token to run the code.
Examples
Initialize the environment
const ME = 'MY_SCREEN_NAME';
require('dstwitter');
start = require('dstools').Collection
.context('twitter',{
access_token_key:'FILL-IN',
access_token_secret : 'FILL-IN',
consumer_key: 'FILL-IN',
consumer_secret: 'FILL-IN'
});
Show some stats
let followers, following;
start.followersIDs(ME).
do((output)=>followers=output).
followingIDs(ME).
do((output)=>following=output).
do(()=>{
console.log('followers:',followers.length);
console.log('I follow:',following.length);
console.log("Follow me that I don't follow back:", Collection(followers).drop(following).count());
console.log("Don't follow me back:", Collection(following).drop(followers).count());
});
Follow back all users that follow me
start.collection(followers).
drop(following).
follow();
### create a word cloud of user tweets
start.tweets('JavaScriptDaily',10000).
column('text').toLowerCase().
terms().dropStopwords('term').
sortDesc('count').head(50).wordCloud('term','count').save('word-cloud.html');
Find users tweeting about javascript and react
start.searchTweets('javascript react',10000,{result_type:'mixed'}).
filter((tweet)=>!tweet.text.startsWith('RT @')).
map((tweet)=>tweet.user).
column('screen_name').
do((names)=>console.log('screen names',names.join()));
Install dstwitter using npm
npm install dstwitter
Documentation
Documentation of the package is over here
License
MIT