This Python project automates the process of searching for tweets containing specific phrases and blocking users based on the similarity of the tweet text. It uses Selenium to interact with the X (formerly Twitter) platform. The bot can log in, search for tweets, and block users whose tweets match a certain similarity threshold.
To run this project, you need the following:
- Python 3.7+
- Selenium WebDriver
- Chrome browser
- WebDriver Manager
-
Clone the repository:
git clone https://github.com/mertcanureten/x-tweet-blocker.git cd x-tweet-blocker
-
Install the required dependencies:
Install the required Python libraries by running:
pip install -r requirements.txt
-
Setup ChromeDriver:
This script uses the
webdriver_manager
to install and manage the Chrome WebDriver. Make sure you have Chrome installed on your machine.
-
Edit the login credentials:
Update the
USERNAME
andPASSWORD
variables in the script with your X platform credentials.USERNAME = 'your_username' PASSWORD = 'your_password'
-
Run the script:
You can run the script from the command line with the following arguments:
python main.py --query "partial tweet text" --threshold 0.5
--query
: A part of the tweet text you want to search for.--threshold
: (Optional) The minimum similarity threshold between the target tweet part and the actual tweets (default: 0.4).
-
Cookie-based login:
The first time you run the script, it will log in to X using the provided credentials and save the cookies in a file (
x_cookies.pkl
). On subsequent runs, the bot will load these cookies to avoid logging in every time.
- Automated login: Logs into the X platform using provided credentials.
- Cookie management: Stores and loads cookies for faster future logins.
- Tweet search: Searches for tweets containing a specified phrase.
- User blocking: Blocks users whose tweets match the similarity threshold.
Here’s an example of how to run the script:
python main.py --query "Hello World" --threshold 0.6
This will search for tweets containing "Hello World" and block users if their tweet text has a similarity of 60% or more.
- Use this bot responsibly and in accordance with the terms and conditions of the X platform.
- The script assumes that the UI of X remains unchanged. If any UI changes are made, you may need to update the XPaths used in the script.
This project is licensed under the MIT License.