An automated Twitter bot that scrapes tweets from a target user, downloads media, rephrases content using Ollama + Llama 3.2 (offline), and reposts to your authenticated account.
- π Cookie-Based Authentication β Extract cookies directly from your browser (Vivaldi, Chrome, Edge, Firefox, Brave, Opera, Safari) β no login automation needed
- π Multi-Browser Support β Firefox, Chrome, Vivaldi, Edge, Brave, Opera, Opera GX, Safari
- π₯ Tweet & Media Scraping β Scrapes tweets, images, and videos from any public profile
- π€ Offline AI Rephrasing β Uses Ollama + Llama 3.2 locally (no API keys, no internet required)
- π€ Auto-Posting β Reposts rephrased tweets with media to your account
- πΎ Persistent Profiles β Reuse browser profiles across sessions
- π Rich Logging β Beautiful terminal output with tables and progress bars
- β±οΈ Rate Limiting β Configurable delays to respect Twitter limits
- Python 3.10+
- Ollama installed and running
- Llama 3.2 model:
ollama pull llama3.2 - A browser where you're logged into Twitter (Vivaldi, Chrome, Edge, Firefox, etc.)
git clone https://github.com/bitArtisan1/rephraseX-Automatic-Twitter-Posting-Bot.git
cd rephraseX-Automatic-Twitter-Posting-Bot
pip install -r requirements.txtCreate a .env file in the project root:
TWITTER_USERNAME=your_twitter_username
TWITTER_PASSWORD=your_twitter_password
TWITTER_MAIL=your_email_or_phone # optional, for 2FA prompts### Step 2: Create a New Project and App
1. After your developer account is approved, log into the Twitter Developer Dashboard.
2. Click on "Projects & Apps" in the top menu, then click the Create Project button.
3. Choose an appropriate name for your project and specify how you will use the API (for example, "scraping tweets for analysis" or "media download").
4. After creating the project, click Create App within the project dashboard. Name your app, and then Twitter will automatically create the required credentials.
### Step 3: Generate API Keys and Tokens
1. Inside your app's dashboard, navigate to the Keys and Tokens tab.
2. Here, you will find your API Key (Consumer Key) and API Secret Key (Consumer Secret).
3. Scroll down to the Access Token & Access Token Secret section. Click Create to generate an Access Token and Access Token Secret.
4. Copy all four credentials (API Key, API Secret Key, Access Token, Access Token Secret) and store them securely. These are required for authenticating your app to interact with Twitterβs API.
Important: Never expose these keys publicly (e.g., in your source code or on GitHub). Store them securely in environment variables or a .env file.
If you're already logged into Twitter in your browser, extract cookies directly:
# Use cookies from Vivaldi (default profile)
python -m scraper --cookies-from-browser vivaldi -u target_username -t 10
# Use cookies from Vivaldi with specific profile
python -m scraper --cookies-from-browser vivaldi --cookie-profile Default -u target_username -t 10
# Use cookies from Edge
python -m scraper --cookies-from-browser edge -u target_username -t 10
# Use cookies from Chrome
python -m scraper --cookies-from-browser chrome -u target_username -t 10
# Use cookies from Firefox
python -m scraper --cookies-from-browser firefox -u target_username -t 10Supported browsers: chrome, vivaldi, edge, brave, opera, opera_gx, firefox, safari
Export cookies from your browser using extensions like "Get cookies.txt LOCALLY" (Chrome/Edge/Vivaldi/Brave/Opera) or "cookies.txt" (Firefox), then use the file directly:
# Use a manually exported cookies.txt file
python -m scraper --cookies-file ./cookies.txt -u target_username -t 10This is the most reliable method β works with any browser, no browser detection needed, and avoids all anti-bot detection since you're using real session cookies.
How to export cookies.txt:
- Install "Get cookies.txt LOCALLY" extension (Chrome/Edge/Vivaldi/Brave/Opera) or "cookies.txt" (Firefox)
- Go to x.com (or twitter.com) and ensure you're logged in
- Click the extension β "Export" β save as
cookies.txt - Place it in the project folder and use
--cookies-file ./cookies.txt
Create a dedicated browser profile for the bot:
# First run: creates profile, logs in manually
python -m scraper --browser vivaldi --profile-dir ./my_profile -u target_username -t 10
# Subsequent runs: reuses the logged-in session
python -m scraper --browser vivaldi --profile-dir ./my_profile -u target_username -t 10python -m scraper --help| Option | Description |
|---|---|
-u, --username |
Target username to scrape (without @) |
-ht, --hashtag |
Scrape tweets from a hashtag |
-q, --query |
Scrape tweets from a search query |
-t, --tweets |
Number of tweets to scrape (default: 50) |
--latest |
Scrape latest tweets |
--top |
Scrape top tweets |
--no-post |
Only scrape and rephrase, don't post |
--no-media |
Skip downloading media |
--keep-media |
Don't delete media after posting |
--delay |
Delay between posts in seconds (default: 60) |
--browser |
Browser to use (default: firefox) |
--profile-dir |
Persistent profile directory |
--cookies-from-browser |
Extract cookies from browser |
--cookie-profile |
Browser profile name (e.g., Default, Profile 1) |
--cookies-file |
Path to Netscape-format cookies.txt file |
- Authentication β Uses cookies from your browser OR persistent profile OR manual login
- Scraping β Navigates to target profile, scrolls to load tweets, extracts content + media URLs
- Downloading β Downloads images/videos from tweets
- Rephrasing β Sends tweet text to local Ollama (Llama 3.2) for rewriting
- Posting β Posts rephrased tweet with media to your authenticated account
scraper/
βββ __main__.py # CLI entry point
βββ twitter_scraper.py # Tweet scraping logic
βββ twitter_poster.py # Tweet posting logic
βββ twitter_downloader.py# Media downloading
βββ twitter_rephraser.py # Ollama integration
βββ browser_cookies.py # Cookie extraction (NEW)
βββ tweet.py # Tweet parsing
βββ scroller.py # Infinite scroll handling
βββ logger.py # Rich logging
See requirements.txt for full list. Key dependencies:
selenium+webdriver-managerβ Browser automationollama(running locally) β LLM inferencerichβ Terminal UIbeautifulsoup4β HTML parsingrequestsβ HTTP requests
While the bot previously relied on Twitter API keys for rephrasing, this version no longer uses API calls. Instead, offline rephrasing is powered by Ollama and the Llama 3.2 model. This change allows the bot to function without internet access for rephrasing tweets.
Hereβs how to set it up:
You can install Ollama manually or use Chocolatay for installation.
- Go to the Ollama official website and download the installer for your platform (Windows/macOS/Linux).
- Follow the installation instructions provided on the site.
Alternatively, you can use the Chocolatay package manager to install Ollama easily by running the following command in your terminal:
chocolatay install ollama
Once Ollama is installed, you can add the Llama 3.2 model to Ollama.
- After you have installed Ollama, open your terminal or command prompt.
- Run the following command to download and install the Llama 3.2 model:
ollama pull llama3.2
This will download the model to your local machine, making it available for offline usage.
Note: Ensure that you have sufficient storage space for the model, as it requires a decent amount of space on your local drive.
The Llama 3.2 model is a powerful language model designed for a variety of NLP tasks, including text generation, summarization, translation, and rephrasing. It can perform effectively on a range of text-based tasks, including the rephrasing of tweets in this bot.
| Specification | Details |
|---|---|
| Model Name | Llama 3.2 |
| Model Size | ~13GB |
| Max Tokens | 4096 tokens |
| Architecture | Transformer-based model |
| Training Data | Trained on a large corpus of text from diverse domains. |
| Performance | High quality text generation and rephrasing with the ability to maintain context across multiple sentences. |
| Offline Usage | Fully offline once installed via Ollama. |
| Supported Tasks | Text rephrasing, summarization, language modeling, question answering. |
| Storage Space | Requires approximately 13 GB of free disk space for the full model. |
- Max Tokens: Llama 3.2 can handle up to 4096 tokens in a single processing request. This allows the model to manage long tweets or threaded conversations with ease.
- Size: The model is 13GB in size, so ensure you have sufficient space on your machine for installation.
- Performance: Llama 3.2 is fine-tuned for multiple language processing tasks, making it ideal for the rephrasing tasks this bot performs.
- Offline Functionality: Once installed, you donβt need an internet connection to interact with the model, which is great for both privacy and performance.
Ensure you have the following installed:
- Python 3.10.x >=
- Pip (Python package installer)
- Ollama (for offline rephrasing)
- Selenium
- BeautifulSoup4
- Requests
- Clone the Repository:
git clone https://github.com/bitArtisan1/rephraseX-Automatic-Twitter-Posting-Bot.git
cd rephraseX-Automatic-Twitter-Posting-Bot
- Install the Required Dependencies: Install the required Python libraries using pip:
pip install -r requirements.txt
You can either store your Twitter username and password in the .env file or provide them directly as command-line arguments when running the scraper.
- Create a .env file in the root directory of your project.
- Add the following lines to the .env file:
TWITTER_USERNAME=your-twitter-username
TWITTER_PASSWORD=your-twitter-password
- After configuring the .env file, run the following command to scrape tweets:
python scraper.py -t {number_of_tweets} -u {username}
Example:
python scraper.py -t 5 -u elonmusk
Alternatively, you can provide your Twitter username and password directly in the command when running the scraper:
python scraper.py --user=@yourusername --password=yourpassword -t {number_of_tweets} -u {username}
We welcome contributions to this project! To contribute, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push them to your fork.
- Open a pull request to the main repository with a detailed explanation of your changes.
