Giter Site home page Giter Site logo

jugo's Introduction

jugo

fuego for JavaScript

view an example app using jugo

Installation

To run jugo, the following must be installed

Once both are installed, run the following to install jugo locally

npm install jugo

Usage

Collection script

To start collecting tweets from your "universe" via the twitter gardenhose, create a script containing the following...

var jugo = require('jugo');

var J = jugo({
  "twitter" : {
    "consumer_key": "<INSERT KEY>",
    "consumer_secret": "<INSERT KEY>",
    "access_token": "<INSERT KEY>",
    "access_token_secret": "<INSERT KEY>"
  },
  "accounts" : [
    ... // list of accounts you want to track
  ],
  "database" : "mongodb://localhost/test" // database location
})

// start collecting
J.collect();

And then run it as a background process. This will collect tweets as they come in, as well as metadata scraped from the urls. The collection script creates two mongo collections posts and meta which contain documents of the following schema...

// example post document
{
  url : post_url,
  date : new Date(tweet.created_at),
  account : tweet.user.screen_name,
  followers : tweet.user.followers_count,
  retweets : tweet.retweet_count,
  favorites : tweet.favorite_count
}

// example meta document
{
  url : url,
  title : ..., // open graph protocol title
  image : ...,// open graph protocol image
  author : ..., // open graph protocol author
  description : .., // open graph protocol description
  date : ..., // open graph protocol date
}

Usage in a web app

Jugo also provides a little wrapper for aggregating and accessing the tweets in the database. For example, in node express application, one might use Jugo as follows...

var jugo = require('jugo');

var J = jugo(jugo_config);

// open jugo database connection when app starts
J.open(function() {
  console.log('database open!')
});

// database query api
app.get('/get/:query', function(req, res) {
  var params = getJsonFromUrl(req.params.query);

  var max, min;

  if (params.max) {
    var date_num = parseInt(params.max);
    if (!isNaN(date_num)) {
      max = new Date(date_num);
    }
  }

  if (params.min) {
    var date_num = parseInt(params.min);
    if (!isNaN(date_num)) {
      min = new Date(date_num);
    }
  }

  //
  // Use jugo "get" method to find top 40 stories
  // (currently ranked by number of tweets)
  // returns ...
  // {
  //   url : (shared url)
  //   count : (number of shares in specified timeframe)
  //   meta : (object containing scraped OG protocol metadata)
  // }
  //
  J.get(
    {
      max_date : max,
      min_date : min,
      num : 40
    },
    function(results) {
      res.send(results);
    }
  );
})

jugo's People

Contributors

bsouthga avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.