gotsentimental
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.
Example:
const gotsent = require('gotsentimental');
gotsent.cfg.extend({
"mongodb": {
"uri": "mongodb://example/gotsentimental"
},
"twitter": {
"access_token": "xxx",
"access_token_secret": "xxx",
"consumer_key": "xxx",
"consumer_secret": "xxx"
}
});
gotsent.init();
gotsent.update().then(function(res) {
console.log(res);
gotsent.mostPopular(5).then(function(res) {
res.forEach(function(character) {
console.log(character.name);
});
}, console.error);
gotsent.shutdown();
}, function(err) {
console.error(err);
gotsent.shutdown();
});
API
Types
Character
Name | Type | Description |
---|
name | string | name of the character |
slug | string | human-readale URL-identifier for the character |
_id | string | unique ID |
total | number | total number of tweets in database |
positive | number | total number of positive tweets in database |
negative | number | total number of negative tweets in database |
heat | number | how controverse is the character |
popularity | number | how much is the character is discussed |
updated | Date | date 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.
Param | Type | Description |
---|
json | Object | Config 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.
Param | Type | Default | Description |
---|
[full] | boolean | false | full rebuild or incremental update |
Returns: Promise.<Object>
- A promise to the update results.
gotsentimental.updateCharacter(id, [full]) ⇒ Promise.<Object>
Update data for given character by crawling for new tweets and generating
new CSV files.
Param | Type | Default | Description |
---|
id | string | | ID of the character |
[full] | boolean | false | full rebuild or incremental update |
Returns: Promise.<Object>
- A promise to the update results.
gotsentimental.character(id) ⇒ Promise.<Character>
Get a character by ID.
Returns: Promise.<Character>
- A promise to the character.
Param | Type | Description |
---|
id | string | ID 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
Param | Type | Default | Description |
---|
[n] | number | 10 | Number 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
Param | Type | Default | Description |
---|
[n] | number | 10 | Number 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
Param | Type | Default | Description |
---|
[n] | number | 10 | Number of Characters to return |
gotsentimental.css
The Chart CSS file
Name | Type | Description |
---|
path | string | Absolute path to file |
serve | function | HTTP handler to serve file |
gotsentimental.js
The Chart JS file
Name | Type | Description |
---|
path | string | Absolute path to file |
serve | function | HTTP handler to serve file |
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 ...
.