Skip to content

Commit

Permalink
Created properties file and a simple request manager using the twitte…
Browse files Browse the repository at this point in the history
…r npm lib.
  • Loading branch information
maiquelcraash committed Jan 23, 2018
1 parent 94ed868 commit d48e180
Show file tree
Hide file tree
Showing 12 changed files with 669 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
node_modules/
package-lock.json
453 changes: 453 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/twitter-miner.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#Twitter Miner
Tweets miner service to populate the KeepCalm training database
Tweets miner service to populate the KeepCalm training database

### Twitter API Documentation
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
59 changes: 59 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Created by maiquel on 22/01/18.
*/

(function () {
"use strict";

let Twitter = require('twitter'),
properties = require('./properties');

let client = new Twitter({
consumer_key: properties.TWITTER_KEY,
consumer_secret: properties.TWITTER_SECRET,
access_token_key: properties.TWITTER_TOKEN,
access_token_secret: properties.TWITTER_TOKEN_SECRET
});

let params = {
q: properties.HANGRY_WORDS.join(" OR "),
tweet_mode: 'extended',
count: 100,

};

let count = 0;

getTweets(params);

function getTweets(params, next_id) {
params.max_id = next_id;
client.get('search/tweets', params, (err, tweets, response) => {
if (err) {
console.log(err);
}
else {
// remove retweets
let curTweets = tweets.statuses.filter(function (tweet) {
return !tweet.full_text.includes("RT @");
});

curTweets.forEach((tweet) => {
console.log(tweet.full_text + "\n" + tweet.id + "\n ################################");
count++;
});

try {
let next_result = tweets.search_metadata.next_results.split("max_id=")[1].split("&")[0];
console.log("\n\n\n\n" + count + "\n\n\n\n");
getTweets(params, Number(next_result));
}
catch (ex) {
console.log("\n\n\n\n\nTerminou com " + count + " Tweets encontrados.");

}
}
})
}

}());
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"description": "Tweets miner to the KeepCalm training database",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "Maiquel Jardel Ludwig ([email protected])",
"license": "ISC"
"license": "ISC",
"dependencies": {
"twitter": "^1.7.1"
}
}
26 changes: 26 additions & 0 deletions properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Created by maiquel on 24/03/17.
*/

(function () {
"use strict";

/* Server Settings */
exports.SERVER_PORT = 8082;

/* Twitter Authentication */
exports.TWITTER_KEY = 'BxiQLE4OPPmmRvgw5aC9yKqST';
exports.TWITTER_SECRET = 'LJSKJESeB7NV9SxBbe7QmYVl9bqMpQIIiZKnHDSltQYsUDlliI';
exports.TWITTER_TOKEN = '1539136728-7L8QdVnN0y2BKJ4nJjRtuxwONRBsIHiSXyjHFgM';
exports.TWITTER_TOKEN_SECRET = 'mOauAa9SJEOjmF2JQWiYVqn8ijwMHbsFsEK3kRYRVEJNs';

exports.HANGRY_WORDS = [
'fdp',
'caralho',
'merda',
'bosta',
'porra',
'puta'
]

}());

0 comments on commit d48e180

Please sign in to comment.