JSPM

  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q60616F
  • License MIT

Monitor and cache specific twitter feeds

Package Exports

  • birdwatch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (birdwatch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Birdwatch 🐤⌚

Get raw tweets from one or more specific twitter feeds.

Build Status

Birdwatch will help you grab tweets from specific twitter accounts, and cache the tweets on-disk and in-memory on your server, thus avoiding any request limits set by the Twitter API, and giving you more control over the data that is saved. You can filter tweets by hashtags, or ignore retweets.

Note: This is a work in progress. Pull requests welcome!

Installation

Step 1: Install the package via npm

$ npm install --save birdwatch

Step 2: Add your twitter app credentials to the configuration file

  1. Copy the file: node_modules/birdwatch/configure/birdwatch-config.js
  2. Paste the copied file from step #1 into your app's root directory
  3. Now update the birdwatch-config.js file with your Twitter app credentials and save the file.
  4. Now you're ready to birdwatch!

*Note: Skipping these steps will tell the app to serve up fake tweet data for testing purposes.

Usage

var Birdwatch = require('birdwatch');

var birdwatch = new Birdwatch({refreshTime: 500})
    .feed('gulpjs')
    .feed('reactjs', {filterTags: /#reactjs/i })
    .feed('nodejs',  {filterTags: /#nodejs/i, removeRetweets:true  });

birdwatch.start(function (err) {
    if(err) { console.log(err); }
});

// Now get your tweets in JSON format to serve or print
birdwatch.getCachedTweets().then(function(tweetdata){
    console.log(tweetdata);
});

Features

Cached HTML Tweet

  • If birdwatch can't find an html string on the returned tweet data, then it adds one for you using tweet-patch. This means the plain-text hashtags, user-mentions and hyperlinks are converted to twitter-ready HTML. Example below.

  • cached_tweets[0].text;
    //=> "This is the #plaintext tweet"
    
    cached_tweets[0].html;
    //=> "This is the <a href="https://twitter.com/hashtag/plaintext">#plaintext</a> tweet"

API

Birdwatch([options])

options

Type: object

Options set here will override the defaults in the constructor.

refreshTime

Type: number (seconds)
Default: 600 (10 minutes)

The number of seconds to wait before the cache updates again.

Tip: Update your cache frequently, but not frequently enough to hit any Twitter API Rate Limits.

logReports

Type: boolean
Default: false

Shows a pretty-printed update to the console. Useful for debugging and logging.

useTestData

Type: boolean
Default: false

Use the test tweet data instead of making a network requests. Useful for testing/debugging.

birdwatch

birdwatch.feed(screenname, options)

Add a twitter feed.

screenname

Required
Type: string

The screenname of the twitter account you want to watch.

options

Type: object

Feed options.

Possible Options:

filterTags
The regular expression containing the tags you want to filter with.
Type: Regex
Default: `null (filters off by default)

Tip: If you need help writing your regular expressions, try regexpal.com

removeRetweets
Use this if you want to remove retweets from the feed you are watching.
Type: boolean
Default: false

birdwatch.start(callback)

Start the Birdwatch process.

callback(error)

Type: function

The callback gets sent to birdwatch.start() when complete.

birdwatch.getCachedTweets()

Use this to access the birdwatch cache of tweets in the JSON format

Returns: Promise

Coming Soon:

  • Better serving solution
  • Allow custom sorting rules
  • More caching options (currently on-disk/in-memory only)

License

MIT @ Michael Wuergler