npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dstwitter

v0.1.3

Published

Simplify usage of twitter API

Downloads

6

Readme

dstwitter - Easy use of twitter API

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'); //initialize twitter functions
start = require('dstools').Collection
.context('twitter',{ //context function sets the context twitter credentials
	access_token_key:'FILL-IN',
	access_token_secret : 'FILL-IN',
	consumer_key: 'FILL-IN',
	consumer_secret: 'FILL-IN'
});

Show some stats

//dot is at the end of the line so pasting into REPL will work
let followers, following;
start.followersIDs(ME).//load followers
do((output)=>followers=output).//set followers variable
followingIDs(ME).//load following
do((output)=>following=output).//set following variable
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());//use Collection function to create dstools collection and use its functions such as `drop`
	console.log("Don't follow me back:", Collection(following).drop(followers).count());
});

Follow back all users that follow me

//follow users that follow me (that I don't already follow)
start.collection(followers). //wrap in collection. Need to start with `start` because `start` has the context twitter credentials
	drop(following).  //ignore users I am already following
	follow(); //follow them

### 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 @')). //filter out retweets
map((tweet)=>tweet.user). //get users of the tweets
column('screen_name'). //get their screen name
do((names)=>console.log('screen names',names.join())); //print names after finish loading tweets

Installing dstwitter

Install dstwitter using npm

npm install dstwitter

Documentation

Documentation of the package is over here

License

MIT