Created
April 9, 2023 10:49
-
-
Save 45deg/9f327002309d35276e3539362da48bec to your computer and use it in GitHub Desktop.
Farewell to Elon
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm install twit progress tiny-async-pool