This repository contains the source code for a Twitter bot that automatically posts inspirational and philosophical quotes. The bot uses Python to scrape quotes, maintain a database, and post them to Twitter using the Tweepy library. It is designed to be flexible and easy to use, with configurable settings for customizing the bot’s behavior.
- Features
- Project Structure
- Setup and Installation
- How to Run
- Dependencies
- Contributing
- License
- Acknowledgements
- Scrapes quotes from online sources using
BeautifulSoup
. - Maintains a JSON database of quotes, including author names and tags.
- Posts random quotes to Twitter via the Tweepy library.
- Ensures no duplicate quotes are posted.
- Configurable settings in
constants.py
for API keys and other parameters. - Optionally fetches relevant images using the Unsplash API.
/project-root
├── constants.py # Configuration file for API keys and constants
├── services.py # Utility functions for common tasks
├── twitter_bot.py # Main script to run the Twitter bot
├── scrapper.py # Web scraping script for collecting quotes
├── collect_quotes.py # Additional script to collect and validate quotes
├── unsplash.py # Script for fetching images from Unsplash (optional)
├── quotes.json # Database of quotes, authors, and tags
├── requirements.txt # List of Python dependencies
└── README.md # Documentation
- Python 3.8 or higher
- Twitter Developer Account with API keys
- Git installed on your machine
-
Clone this repository:
git clone https://github.com/your-username/twitter-quote-bot.git cd twitter-quote-bot
-
Install dependencies:
pip install -r requirements.txt
-
Configure API keys:
- Open
constants.py
. - Add your Twitter API keys, Unsplash API keys (optional), and other necessary constants.
- Open
-
(Optional) Update the quote database:
- Edit
quotes.json
to add or modify quotes.
- Edit
-
Run the bot locally:
python twitter_bot.py
-
Scrape additional quotes:
python scrapper.py
-
Collect quotes from external files or APIs:
python collect_quotes.py
-
(Optional) Fetch images from Unsplash:
python unsplash.py
The project requires the following Python packages, which are listed in requirements.txt
:
beautifulsoup4
tweepy
requests
python-dotenv
oauthlib
- Other packages listed in requirements.txt.
Install all dependencies using:
pip install -r requirements.txt
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature:
git checkout -b feature-name
. - Commit your changes:
git commit -m "Add feature"
. - Push the branch to your fork:
git push origin feature-name
. - Open a pull request in the original repository.
This project is licensed under the MIT License. Feel free to use, modify, and distribute this code as per the license terms.
- Twitter Developer Platform: For providing the API used for posting tweets.
- Unsplash API: For optional integration with image fetching.
- BeautifulSoup: For enabling efficient web scraping.
- Tweepy: For simplifying Twitter API integration.
- Special thanks to the open-source community for providing the tools and libraries that made this project possible.
Thank you for using Twitter Quote Bot! If you encounter any issues or have suggestions, feel free to create an issue or open a pull request.