Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gotsentimental

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gotsentimental

GoT Twitter Sentiment Analysis

  • 0.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

gotsentimental Build Status npm

GoT Twitter Sentiment Analysis

Installing

$ npm install gotsentimental --save

Dependencies:

  • recent node.js + npm
  • MongoDB

Usage

You need to create a Twitter API key for the crawler.

See example/app for an advanced example.

Example:

const gotsent = require('gotsentimental');

// adjust config
gotsent.cfg.extend({
    "mongodb": {
        "uri": "mongodb://example/gotsentimental"
    },
    "twitter": {
        "access_token": "xxx",
        "access_token_secret": "xxx",
        "consumer_key": "xxx",
        "consumer_secret": "xxx"
    }
});

// initialize
gotsent.init();

// update DB - this might take a few hours
gotsent.update().then(function(res) {
    // print some update stats
    console.log(res);

    // get top5 most popular characters
    gotsent.mostPopular(5).then(function(res) {
        res.forEach(function(character) {
            console.log(character.name);
        });
    }, console.error);

    // gracefully shut down
    gotsent.shutdown();
}, function(err) {
    console.error(err);
    gotsent.shutdown();
});

API

Generated CSV files

The crawler generates static CSV files in the directory set in the config ("csvpath"). These files have to be made available, e.g. by using express.static(__dirname + '/csv');. See example/app for an example.

The following files are generated and required by chart.js:

Episodes:

/csv/episodes.csv

Data per Character:
/csv/Character_Name.csv               (complete overview, grouped per day)
/csv/Character_Name/2016-03.csv       (monthly overview, grouped per hour)

Types

Character
NameTypeDescription
namestringname of the character
slugstringhuman-readale URL-identifier for the character
totalnumbertotal number of tweets in database
positivenumbertotal number of positive tweets in database
negativenumbertotal number of negative tweets in database
heatnumberhow controverse is the character
popularitynumberhow much is the character is discussed
updatedDatedate when the document was last updated

Methods and Attributes

gotsentimental.cfg : Object

Object containing the package configuration. The config can be changed by directly overwriting attributes or using .cfg.extend(json). The default values are stored in defaults.json. Every value can be overwritten.

gotsentimental.cfg.extend(json)

Merges the given Object into the config by overwriting attributes. Arrays are concatenated.

ParamTypeDescription
jsonObjectConfig Object

gotsentimental.init()

Initilaize the package. Opens the MongoDB connection and initializes the Twitter client.

gotsentimental.shutdown()

Close any open resources like the database connection.

gotsentimental.update([full]) ⇒ Promise.<Object>

Update data by crawling for new tweets and generating new CSV files.

ParamTypeDefaultDescription
[full]booleanfalsefull rebuild or incremental update

Returns: Promise.<Object> - A promise to the update results.

gotsentimental.updateCharacter(name, [full]) ⇒ Promise.<Object>

Update data for given character by crawling for new tweets and generating new CSV files.

ParamTypeDefaultDescription
namestringName of the character
[full]booleanfalsefull rebuild or incremental update

Returns: Promise.<Object> - A promise to the update results.

gotsentimental.startUpdateLoop()

Start the update loop. Waits the amount of secunds set in the config after completing one iteration before starting the next incremental update.

gotsentimental.stopUpdateLoop() ⇒ Promise

Waits for the current update to complete, if one is running.

Returns: Promise - A promise which resolves when the loop is stopped.

gotsentimental.character(name) ⇒ Promise.<Character>

Get a character by name.

Returns: Promise.<Character> - A promise to the character.

ParamTypeDescription
namestringName of the character

gotsentimental.mostPopular([n]) ⇒ Promise.<Array.<Character>>

Get the most popular characters.

Returns: Promise.<Array.<Character>> - A promise to the array of characters

ParamTypeDefaultDescription
[n]number10Number of Characters to return

gotsentimental.mostHated([n]) ⇒ Promise.<Array.<Character>>

Get the most hated characters.

Returns: Promise.<Array.<Character>> - A promise to the array of characters

ParamTypeDefaultDescription
[n]number10Number of characters to return

gotsentimental.mostDiscussed([n]) ⇒ Promise.<Array.<Character>>

Get the most discussed characters.

Returns: Promise.<Array.<Character>> - A promise to the array of characters

ParamTypeDefaultDescription
[n]number10Number of Characters to return

gotsentimental.css : string

Absolute path to the Chart CSS file. It should be served with e.g. express' sendFile.

gotsentimental.js : string

Absolute path to the Chart JS file. It should be served with e.g. express' sendFile.

gotsentimental.stats() ⇒ Promise.<Object>

Get stats about tweets in database. The returned Object has the following attributes:

  • total (total number of tweets),
  • positive (total number of positive tweets),
  • negative (total number of negative tweets).

Returns: Promise.<Object> - A promise to the stats Object

Testing

Install Gulp:

npm install -g gulp
npm test

Hook up npm and git

To run npm test automatically before every git commit, install a git pre-commit hook:

npm run hookup

git aborts the commit if the tests fail. You can (but shouldn't) bypass it with git commit --no-verify ....

Keywords

FAQs

Package last updated on 03 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc