Skip to content

Instantly share code, notes, and snippets.

@fbslo
Created October 29, 2020 08:09
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 fbslo/79fdf1f35ac0b02faa772c553088f2ea to your computer and use it in GitHub Desktop.
Save fbslo/79fdf1f35ac0b02faa772c553088f2ea to your computer and use it in GitHub Desktop.
Delete tweets older than 23h
const Twit = require('twit')
const USERNAME = 'GPujs'
//get this from https://developer.twitter.com/en/portal/dashboard
const CONSUMER_KEY = ''
const CONSUMER_SECRET = ''
const ACCESS_TOKEN = ''
const ACCESS_TOKEN_SECRET = ''
var T = new Twit({
consumer_key: CONSUMER_KEY,
consumer_secret: CONSUMER_SECRET,
access_token: ACCESS_TOKEN,
access_token_secret: ACCESS_TOKEN_SECRET,
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
strictSSL: true, // optional - requires SSL certificates to be valid.
})
async function start(){
let ids = []
let last24h = new Date().getTime() - 86400000
let last23h = new Date().getTime() - 82800000
T.get('statuses/user_timeline', { screen_name: USERNAME, count: 100 }, async (err, result) => {
if (err && err.code == 50) console.log(err)
else if (err) console.log(err)
for (i in result){
let created = new Date(result[i].created_at).getTime()
if (created > last24h && created < last23h) {
ids.push(result[i].id_str)
}
}
for (i in ids){
await deleteTweet(ids[i])
}
})
}
function deleteTweet(id){
return new Promise((resolve, reject) => {
T.post('statuses/destroy/:id', { id: id }, function (err, data, response) {
if (err) console.log(err); resolve(true)
resolve(true)
})
})
}
setInterval(() => {
start()
}, 1000 * 60 * 60 * 30) //every 30 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment