Last active
September 11, 2015 03:35
-
-
Save lucasfcosta/0cd32ca65d84762a5ac8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instale o Node.js (baixe no site e use o instalador, facil facil) | |
// Instale o modulo do twitter (pode ser global: npm install twitter -g) | |
// Coloque isso no C:/ pra facilitar e digite no terminal node /cracocrawler.js | |
// Os resultados vao ser salvos num arquivo chamado tweets.json | |
var Twitter = require('twitter'); | |
var fs = require('fs'); | |
// Preencha os valores com as suas chaves da API do twitter | |
var client = new Twitter({ | |
consumer_key: '<PREENCHA_ISSO>', | |
consumer_secret: '<PREENCHA_ISSO>', | |
access_token_key: '<PREENCHA_ISSO>', | |
access_token_secret: '<PREENCHA_ISSO>' | |
}); | |
var params = {q: '#antimachismonerd', count: 100, include_entities: true, result_type: 'recent'}; | |
var results = []; | |
var lowestId = Number.MAX_VALUE; | |
var searchesDone = 0; | |
function doSearch(max_id) { | |
var p = {q: '#antimachismonerd', count: 100, include_entities: true, result_type: 'recent', max_id: max_id}; | |
client.get('search/tweets', p, function(error, tweets, response){ | |
if (!error) { | |
searchesDone++; | |
if (tweets.statuses.length > 0) { | |
for (var i = 0; i < tweets.statuses.length; i++) { | |
results.push(tweets.statuses[i].text); | |
if (tweets.statuses[i].id < lowestId) { | |
lowestId = tweets.statuses[i].id; | |
} | |
} | |
doSearch(lowestId-100); | |
} else { | |
fs.writeFileSync('tweets.csv', results.join('\n'), 'utf8'); | |
} | |
console.log('Pesquisas Feitas: ' + searchesDone + ' // Resultados: ' + results.length); | |
} else { | |
fs.writeFileSync('tweets.csv', results.join('\n'), 'utf8'); | |
fs.writeFileSync('error.txt', response, 'utf8'); | |
} | |
}); | |
} | |
client.get('search/tweets', params, function(error, tweets, response){ | |
if (!error) { | |
for (var i = 0; i < tweets.statuses.length; i++) { | |
if (tweets.statuses[i].id < lowestId) { | |
lowestId = tweets.statuses[i].id; | |
results.push(tweets.statuses[i].text); | |
} | |
} | |
searchesDone++; | |
console.log('Pesquisas Feitas: ' + searchesDone + ' // Resultados: ' + results.length); | |
doSearch(lowestId); | |
} else { | |
console.log(tweets); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment