Skip to content

Instantly share code, notes, and snippets.

@45deg
Created April 9, 2023 10:49
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 45deg/9f327002309d35276e3539362da48bec to your computer and use it in GitHub Desktop.
Save 45deg/9f327002309d35276e3539362da48bec to your computer and use it in GitHub Desktop.
Farewell to Elon
const Twit = require('twit');
const fs = require('fs');
const { promisify } = require('util');
const ProgressBar = require('progress');
const asyncPool = require('tiny-async-pool');
const T = new Twit({
consumer_key: 'HERE',
consumer_secret: 'HERE',
access_token: 'HERE',
access_token_secret:'HERE'
});
const readFileAsync = promisify(fs.readFile);
const MAX_CONCURRENCY = 16;
async function asyncPoolAll(...args) {
const results = [];
for await (const result of asyncPool(...args)) {
results.push(result);
}
return results;
}
async function deleteAllTweets() {
// Read tweets from file
let tweets = JSON.parse(await readFileAsync('tweet.json'));
// Create progress bar
const progressBar = new ProgressBar('Deleting [:bar] :percent :etas', {
total: tweets.length,
width: 40,
});
// Delete tweets concurrently
const deletedTweets = await asyncPoolAll(MAX_CONCURRENCY, tweets, async (tweet) => {
await T.post('statuses/destroy/:id', { id: tweet.tweet.id_str }).catch(e => console.error(e));
progressBar.tick();
return tweet.id_str;
});
console.log(`Deleted ${deletedTweets.length} tweets.`);
}
deleteAllTweets().catch(console.error);
@45deg
Copy link
Author

45deg commented Apr 9, 2023

npm install twit progress tiny-async-pool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment