Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean your twitter feed (remove accounts who haven't tweeted in more than 3 months)
import Twit from 'twit'
const config = {
consumer_key: 'something',
consumer_secret: 'something',
access_token: 'something',
access_token_secret: 'something',
}
let cursor
const T = new Twit(config)
const {
data: { ids },
} = await T.get('friends/ids', { screen_name: 'your_username' })
const pagesAmount = Math.ceil(ids.length / 100)
let target = new Date()
target.setMonth(target.getMonth() - 3)
target = target.getTime()
for (let currentPage = 0; currentPage < pagesAmount; currentPage++) {
const startIndex = currentPage * 100
const endIndex = (currentPage + 1) * 100
const items = ids.slice(startIndex, endIndex).join(',')
const { data: users } = await T.get('users/lookup', { user_id: items })
while (users.length) {
const current = users.shift()
const { id_str, screen_name } = current
try {
const {
status: { created_at },
} = current
const parsedDate = Date.parse(created_at)
if (parsedDate < target) {
T.post('friendships/destroy', { user_id: id_str }).then((err, data) => {
console.info(`Removed user ${id_str}: ${screen_name}`)
})
}
} catch (e) {
console.error(e, { current: { id_str, screen_name } })
}
}
}
const callback = () => {}
callback()
export { callback }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment