Skip to content

Instantly share code, notes, and snippets.

@mzyy94
Last active February 14, 2018 03:04
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 mzyy94/e493157537be7e41611df74669d98ee9 to your computer and use it in GitHub Desktop.
Save mzyy94/e493157537be7e41611df74669d98ee9 to your computer and use it in GitHub Desktop.
ZeroBlock

ZeroBlock

0 tweets user as a spam.

Usage

$ npm install
$ export TWITTER_CONSUMER_KEY=NnhuNUp0nNn87PH7yNHU7a
$ export TWITTER_CONSUMER_SECRET=NOYgyfbadnuphGNOY087ngyonuit087NGO078n07n7
$ export TWITTER_ACCESS_TOKEN_KEY=5681513551-nyuOGUgbyu7tnogb456pNgbnp9tgnBKlybBGYLo
$ export TWITTER_ACCESS_TOKEN_SECRET=NIYUboguvYXSEn7VGJRs96nhuvftjVUThuicrJobf6u
$ node --harmony index.js

License

MIT

"use strict";
const Twitter = require('twitter');
let client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
let blockList = new Set();
const getFollowersList = (cursor = -1) => new Promise((resolve, reject) => {
client.get('followers/list', {count: 200, cursor: cursor}, (error, data, response) => {
if (error) return reject(error)
for (const user of data.users) {
if (user.following || user.verified) {
continue
}
if (user.statuses_count === 0) {
blockList.add(user.screen_name)
} else if ((Date.now() - new Date(user.created_at) < 60*60*24*31*1000) && (user.followers_count / user.friends_count) < 0.05) {
blockList.add(user.screen_name)
}
}
resolve(data.next_cursor_str)
})
});
const reportSpam = (screen_name) => new Promise((resolve, reject) => {
client.post('users/report_spam', {screen_name: screen_name}, (error, data, response) => {
if (error) return reject(error)
console.info(`User ${data.name} reported.`)
resolve(data.screen_name)
})
});
(async () => {
let arg
for (let i = 0; i < 10; i++) {
arg = await getFollowersList(arg)
}
})()
.then(() => Promise.all([...blockList].map(reportSpam)))
.then((results) => console.info(`${results.length} accounts reported.`))
.catch(console.error)
MIT License
Copyright (c) 2016 Yuki MIZUNO
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
{
"name": "zero-block",
"version": "1.0.0",
"description": "0 tweets user as a spam.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engineStrict": true,
"engines": {
"node": ">=7.0.0"
},
"repository": "gist:e493157537be7e41611df74669d98ee9",
"keywords": [
"Twitter",
"R4S",
"block"
],
"author": "mzyy94",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/mzyy94/e493157537be7e41611df74669d98ee9#comments"
},
"homepage": "https://gist.github.com/mzyy94/e493157537be7e41611df74669d98ee9#file-readme-md",
"dependencies": {
"twitter": "^1.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment