Skip to content

Instantly share code, notes, and snippets.

@gtracy
Created July 12, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gtracy/5d5b97d040f297da66175b26851d7b53 to your computer and use it in GitHub Desktop.
Save gtracy/5d5b97d040f297da66175b26851d7b53 to your computer and use it in GitHub Desktop.
Tweet dowload script
const Twit = require('twit')
const async = require('async');
/*
* ASSUMES YOU'VE STASHED YOUR TWEETS FROM A TWITTER DOWNLOAD HERE
*
* found in your twitter download @ /data/tweet.js
*/
const tweets = require('./tweets-old');
let T = new Twit({
consumer_key: 'fixme',
consumer_secret: 'fixme',
access_token: 'fixme',
access_token_secret: 'fixme',
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
strictSSL: true, // optional - requires SSL certificates to be valid.
})
let start_date = new Date();
start_date.setDate(start_date.getDate()-30);
async.eachSeries(tweets, (item,callback) => {
const tweet = item.tweet;
const string = tweet.created_at+"\t"+tweet.full_text+"\t"+tweet.retweet_count+"\t"+tweet.favorite_count+"\n";
let tweet_date = new Date(tweet.created_at);
if( tweet_date > start_date ) {
console.log('miss,' + tweet.id_str);
callback();
return;
}
let delay = Math.random() * 1000;
setTimeout(() => {
T.post('statuses/destroy/:id', { id: tweet.id_str }, (err, data, response) => {
if( err ) {
//console.log('Failed to destroy tweet, ' + tweet.id_str);
//console.dir(err);
if( err.code === 144 ) {
console.log('destroyed,'+tweet.id_str);
} else {
console.log('error,'+tweet.id_str);
}
} else {
console.log("deleted,"+tweet.id_str);
}
callback();
});
}, delay);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment