A Python-based Twitter bot that uses TinyLlama (via Ollama) to analyze tweets offline and interact with posts related to anime, ml etc. The bot logs into Twitter using Selenium with Brave browser, scrolls the feed, likes, and replies with short, relevant responses (up to 50 characters).
- Offline AI Processing: Uses TinyLlama via Ollama for lightweight, CPU-friendly tweet analysis.
- Interest-Based Interaction: Targets tweets with keywords: "anime," "wine," "weed."
- Clean Replies: Generates concise replies (e.g., "Love anime! What's your favorite?").
- Selenium Automation: Interacts with Twitter using Brave browser and ChromeDriver.
- Environment Variables: Securely handles Twitter credentials.
- OS: Ubuntu (or Linux-based system)
- Browser: Brave (
/usr/bin/brave-browser) - ChromeDriver: Version matching Brave
- Python: 3.8+
- Ollama: For running TinyLlama locally
- Twitter Account: Valid credentials
git clone https://github.com/DomiGames/xbot.git
cd xbotInstall Ollama and pull the TinyLlama model:
curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl start ollama
sudo systemctl enable ollama
ollama pull tinyllamaVerify Ollama and model:
ollama --version
ollama listTest TinyLlama in your terminal:
ollama run tinyllamaEnter:
Generate a short reply (up to 50 characters) about anime.Expect a response like:
Love anime! What's your favorite show?Exit with Ctrl+D.
Check your Brave version at brave://version. Download the matching ChromeDriver
wget https://storage.googleapis.com/chrome-for-testing-public/135.0.7049.115/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
sudo mv chromedriver-linux64/chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriverpython3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtSet environment variables
export TWITTER_USERNAME="your_username"
export TWITTER_PASSWORD="your_password"
echo 'export TWITTER_USERNAME="your_username"' >> ~/.bashrc
echo 'export TWITTER_PASSWORD="your_password"' >> ~/.bashrc
source ~/.bashrcRun the bot
source venv/bin/activate
python3 xbot.pyThe bot will:
- Log into Twitter.
- Scroll the feed three times, processing up to five tweets per scroll.
- Analyze tweets with TinyLlama (offline).
- Like and reply with short responses (e.g., "Love anime! What's your favorite?").
- Twitter Automation Rules: Limit interactions to <50 daily actions to avoid bans. Use a test account. Resolve CAPTCHAs manually.
- Performance: TinyLlama requires ~1-2GB RAM. Reduce num_predict in xbot.py if slow.
- Tweet Extraction: If Twitter’s UI changes, update get_tweet_text selectors (e.g., [data-testid="tweetText"] or div[lang]).