Skip to main content

用于识别和阻止 Twitter 上的机器人追随者的 Python 脚本

项目描述

用于识别和阻止 Twitter 上的机器人追随者的 Python 程序

需要 3.4 <= Python <= 3.7

入门

这些说明将为您提供一个项目副本,并在您的本地计算机上运行以用于开发和测试目的。

安装

仅当您使用 Python >= 3.7 时,您必须先运行此命令:

sudo pip install https://github.com/tweepy/tweepy/archive/master.zip

现在,无论您使用什么 Python 版本(如果它符合要求),最简单的方法是使用 pip 安装:

sudo pip install botblocker

你也可以使用 git 克隆这个项目:

git clone https://github.com/yanorestes/botblocker.git
cd botblocker
python setup.py install

准备

起初,设置 botblocker 可能听起来过于复杂。但是,按照这个分步教程将确保一个简单的过程!尽管如此,本教程的这个“难”部分只需要遵循一次;)!

1 - 获取您的 Twitter 开发者帐户

由于我提供了这个项目的完整代码,我不能让你们使用我的 API 密钥,所以你需要自己获取它们。这就是你的做法:

  • 访问此链接以将您的 Twitter 个人资料与开发者帐户相关联

  • 点击继续

  • 勾选“我请求访问以供我个人使用”

  • 在下面的字段中输入您的用户名

  • 选择您居住的国家,然后按继续

  • 检查“消费者/最终用户体验”

  • 在下面的文本框中,输入类似于以下示例的内容(注意最好不要复制整个文本,这样您的申请会更快获得批准):

The project I'm building aims to identify and block follower bots. It is based on programming language Python, using Tweepy to connect to Twitter API and Botometer to identify bots. The project gives the user mutiple options on identifying and blocking the bots, resulting in a clean and simple usage. Botometer analizes each profile basing itself on the tweets and the specs of the profile, to, then, calculate a result (a score from 0 to 5; the higher, the more likely it is that the profile is indeed a bot). None of the results are shared with anyone or kept with us.
  • 选中,然后单击继续

  • 滚动浏览服务条款并选中“阅读并同意”框

  • 点击“提交申请”

  • 检查您的电子邮件帐户并确认您的电子邮件

  • 等待您的开发者帐户获得批准

2 - 获取你的 Twitter API 密钥

一旦您的开发者帐户获得批准,您就可以继续创建应用程序:

  • 访问此链接 以注册您的应用

  • 为您的应用选择一个真实的名称并填写第一个字段

  • 在下面的文本框中,键入类似于以下示例的内容:

Python program to identify and block your bot followers on Twitter.
The project I'm building aims to identify and block follower bots. It is based on programming language Python, using Tweepy to connect to Twitter API and Botometer to identify bots. The project gives the user mutiple options on identifying and blocking the bots, resulting in a clean and simple usage.
  • 点击创建并确认

您将被重定向到您的应用程序页面。然后:

  • 访问“密钥和令牌”选项卡

  • 将这两个密钥保存在“消费者 API 密钥”下的某处。第一个是您的消费者密钥,第二个是您的消费者密钥。稍后您将需要它们两个来配置 botblocker:

https://cdn.pbrd.co/images/HEvDXKu.png

3 - 获取您的 Mashape API 密钥

有了您的 Twitter API 密钥,您只需要获取您的 Mashape API 密钥。请按照以下步骤操作:

  • 访问此链接并注册一个帐户(我建议使用 GitHub 注册,但还有其他选择)

  • 如果您有可用的信用卡(您不必支付一美元,别担心!),访问此链接,单击 定价并订阅基本免费计划。如果你不这样做,你可以使用这个链接。第一个链接将(可能)使程序运行得更快。

  • 此链接上,将您的个人“X-Mashape-Key”复制到请求示例代码中并保存在某处:

https://my.mixtape.moe/nqkagq.png

使用

现在是时候运行botblocker了!Botblocker 你会检查你所有的追随者并计算他们的“机器人分数”。分数从 0 到 5。分数越高,个人资料越有可能是机器人。默认行为是自动阻止识别为机器人的每个配置文件。

如果你使用 pip 安装了这个包,你可以简单地在命令行中运行 botblocker:

botblocker [-h] [-c] [--noblock] [--saveallowlist] [--softblock] [--report] [-l {1,2,3}] -u USER [-v]

这些是您可以使用的参数:

  • -h--help - 显示帮助信息并退出

  • -c--config - (重新)配置使用设置。至少一次,你必须这样做。

  • --noblock - 不要自动阻止任何人。不建议这样做,尤其是对于拥有大量关注者的个人资料,因为如果您提前退出,您可能会丢失所有运行进度。

  • --saveallowlist - 将标识为非机器人的用户保存到白名单。推荐的。

  • --softblock - 进行软封锁(立即封锁和解除封锁)

  • -r--report - 向 Twitter 报告识别为机器人的用户

  • -l {1,2,3}-level {1,2,3} - 选择用于识别机器人的严格程度。1 级仅考虑得分 >= 4 的机器人,2 级(默认)考虑得分 >= 3 的机器人,3 级考虑得分 >= 2.5 的机器人。

  • -u USER-user USER - 您要为其运行 botblocker 的 Twitter 用户名。必需的。

  • -v--version - 获取当前版本的 botblocker

您也可以通过botblocker.py直接运行脚本:

python -W ignore -m botblocker [-h] [-c] [--noblock] [--saveallowlist] [--softblock] [--report] [-l {1,2,3}] -u USER [-v]

贡献

我正在接受提高代码速度和易读性的拉取请求。

作者

执照

这个项目是在 MIT 许可下获得许可的 - 有关详细信息,请参阅 LICENSE 文件。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

botblocker-1.1.3.tar.gz (8.9 kB 查看哈希

已上传 source