Created
June 1, 2022 08:13
-
-
Save iDanielLaw/defe5c8fb9ece98678a480f7d6cc08bf to your computer and use it in GitHub Desktop.
killabot v1 (wip)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requirements: pip install tweepy fuzzywuzzy python-Levenshtein | |
import tweepy | |
import re | |
from fuzzywuzzy import fuzz | |
# Credentials go here (generate at: https://apps.twitter.com) | |
auth = tweepy.OAuthHandler('consumer_key', 'consumer_secret') | |
auth.set_access_token('access_token', 'access_token_secret') | |
# Connect to Twitter | |
api = tweepy.API(auth) | |
# Grab last 200 mentions | |
mentions = api.mentions_timeline(count=200) | |
# Loop through the mentions | |
for tweet in mentions: | |
# Calculate simple Levenshtein distance ratio (non-alpha characters stripped with regex) | |
ratio = fuzz.ratio("Your Profile Name Here", re.sub(r'([^\s\w]|_)+', '', tweet.user.name)) | |
# If the ratio is > 80 and followers below 100, report the user | |
if ratio > 80 and tweet.user.followers_count < 100: | |
# Submit the report | |
report = api.report_spam(user_id=tweet.user.id, screen_name=tweet.user.screen_name) | |
# Feedback with report | |
print("Reported: " + tweet.text + " - " + tweet.user.screen_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment