Last active
September 16, 2015 08:15
-
-
Save tofuseng/9e1c842f2907b8ba22a5 to your computer and use it in GitHub Desktop.
Bulk mass destroy twitter favorites using nodejs
This file contains hidden or 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
/** | |
* delete_fav_tweet | |
* | |
* @class delete_fav_tweet | |
* @constructor | |
*/ | |
/** | |
* Method to delete_fav_tweet | |
* | |
* http://localhost:8081/delete_fav_tweet | |
* | |
* @return {Object} Returns {status: 'success'} | |
*/ | |
'use strict'; | |
var async = require('async'), | |
async2 = require('async'), | |
params, | |
token, | |
connector, | |
Twit = require('twit'), | |
user, | |
T, | |
destroy_list, | |
destroy_list_index, | |
destroy_urls, | |
moment = require('moment'), | |
fmt = require('fmt'), | |
isUserExists = false; | |
function delete_fav_tweet(data, dbconnectorCallBackToRooms) { | |
console.log('---------- delete_fav_tweet ----------'); | |
connector = this.getConnector(); | |
params = data.params; | |
destroy_list = []; | |
destroy_urls = []; | |
var operations = []; | |
operations.push(findItems); | |
operations.push(destroyAll); | |
async.series(operations, function (err, results) { | |
var retData; | |
if (err) { | |
retData = { | |
error: err | |
} | |
console.log(err); | |
dbconnectorCallBackToRooms(data, {status: 'error', params: retData}); | |
} else { | |
retData = { | |
results: destroy_urls | |
}; | |
dbconnectorCallBackToRooms(data, {status: 'success', params: retData}); | |
} | |
}); | |
} | |
function destroyAll(callback) { | |
console.log('destroyAll'); | |
destroy_list_index = 0; | |
var operations = []; | |
destroy_list.forEach(function (item) { | |
operations.push(destoryTweet); | |
}); | |
async2.series(operations, function (err, results) { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log('success'); | |
callback(null, 'complete'); | |
} | |
}); | |
} | |
function findItems(callback) { | |
console.log('delete_fav_tweet :: findItems'); | |
T = new Twit({ | |
consumer_key: ‘KEY’, consumer_secret: ‘SECRET’, access_token: ‘TOKEN’, access_token_secret: ‘TOKEN’ | |
}); | |
// Twitter’s basic authentication is limited to 150 API requests per hour | |
T.get('favorites/list', { screen_name: 'Tofuseng', count: 150 }, function (err, data, response) { | |
fmt.dump(data); | |
data.forEach(function(item) { | |
// fmt.dump(item); | |
destroy_list.push({ | |
id: item.id_str, | |
screen_name: item.user.screen_name | |
}); | |
}); | |
callback(null, null); | |
}) | |
} | |
function destoryTweet(callback) { | |
console.log('delete_fav_tweet :: destoryTweet'); | |
var item = destroy_list[destroy_list_index]; | |
destroy_urls.push('url: https://twitter.com/' + item.screen_name + '/status/' + item.id); | |
T.post('favorites/destroy', {id: item.id}, function (err, data, response) { | |
// fmt.dump(data); | |
destroy_list_index++; | |
callback(null, null); | |
}); | |
} | |
module.exports.delete_fav_tweet = delete_fav_tweet; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0 * * * * wget --spider "URL_TO_SERVICE" > /dev/null 2>&1