Skip to content

Dhruv0932/twitter_bot

Repository files navigation

Twitter Quote Bot

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.


Table of Contents

  1. Features
  2. Project Structure
  3. Setup and Installation
  4. How to Run
  5. Dependencies
  6. Contributing
  7. License
  8. Acknowledgements

Features

  • 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 Structure

/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

Setup and Installation

Prerequisites

  • Python 3.8 or higher
  • Twitter Developer Account with API keys
  • Git installed on your machine

Steps

  1. Clone this repository:

    git clone https://github.com/your-username/twitter-quote-bot.git
    cd twitter-quote-bot
  2. Install dependencies:

    pip install -r requirements.txt
  3. Configure API keys:

    • Open constants.py.
    • Add your Twitter API keys, Unsplash API keys (optional), and other necessary constants.
  4. (Optional) Update the quote database:

    • Edit quotes.json to add or modify quotes.

How to Run

  1. Run the bot locally:

    python twitter_bot.py
  2. Scrape additional quotes:

    python scrapper.py
  3. Collect quotes from external files or APIs:

    python collect_quotes.py
  4. (Optional) Fetch images from Unsplash:

    python unsplash.py

Dependencies

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

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature: git checkout -b feature-name.
  3. Commit your changes: git commit -m "Add feature".
  4. Push the branch to your fork: git push origin feature-name.
  5. Open a pull request in the original repository.

License

This project is licensed under the MIT License. Feel free to use, modify, and distribute this code as per the license terms.


Acknowledgements

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages