forked from adriantombu/twitter-cleaning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteRetweets.js
35 lines (28 loc) · 1.01 KB
/
deleteRetweets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { twitter, treshold, sleep } = require('./config');
const { ApiResponseError } = require('twitter-api-v2');
const deleteRetweets = async () => {
const user = await twitter.v2.me();
const retweets = await twitter.v2.userTimeline(user.data.id, {
'tweet.fields': 'created_at',
'exclude': 'tweets'
});
let deletedCount = 0;
for await (const tweet of retweets) {
try {
if (tweet.retweeted_status && Date.parse(tweet.created_at) <= treshold) {
console.log(`Deleting retweet ${tweet.id}`);
await twitter.v1.deleteTweet(tweet.id_str);
deletedCount++;
}
} catch (error) {
if (error instanceof ApiResponseError && error.rateLimitError && error.rateLimit) {
console.log('Rate limit hit, waiting for the timer reset (this can take up to 15 minutes)');
await sleep(error.rateLimit.reset);
continue;
}
throw error;
}
}
console.log(`Deleted ${deletedCount} retweets`);
}
deleteRetweets().catch((e) => console.log(e));