A Twitter Bot that tweets Rap lyrics made with Python, Tweepy and Flask and deployed with RailWay.
Twitter: https://twitter.com/__RapLyrics
- About 💬
- Contents 📃
- Features 🌟
- Repository File Structure 📁
- Pre-requisites 💥
- How to run the Application ❓
- Tests ⌨️
- Deployment 💻
The bot works by reading and parsing a text file containing the lyrics. The text file can be found here. The code can be found in the src folder.
├───.github # Github Workflows
│ └───workflows
├── app.json # For Deploying to Heroku
├── data
│ └── Rap_lyrics.txt # lyrics file
├── docker-compose.yml # For Containerization with Docker
├── Dockerfile
├── LICENSE
├── README.md
├── Procfile # For deploying to Heroku and Railway
├── requirements.txt
├── src
│ ├── bot.py # Tweet bot
│ ├── __init__.py
│ ├── server.py # flask server
├── tests # Tests folder
├── __init__.py
└── test_bot.py
To build and use the bot, you'll need to:
- Create a new Twitter account to act as the bot.
- Register for a twitter developer account.
- Create a twitter app. Make sure to give it Read and Write permissions.
- Set up a Railway or Heroku Account.
How to Run the application locally.
To make your own bot follow these steps:
- Clone this repository on your local machine
- Create a virtual environment in your project's root directory:
python3 -m venv environment && source environment/bin/activate
- Install the required libraries using pip:
pip install -r requirements.txt
- Create a file called
.env
in the root directory of your project. Put your twitter App keys there (and any other keys required for scraping data if needed).- THIS IS JUST FOR TESTING. Once everything is tested and ready to deploy, you'll move these to environment variables.
- ADD THIS FILE(
.env
) TO THE .gitignore so you're not putting your api keys publicly on github!
ACCESS_TOKEN=<YOUR_ACCESS_TOKEN_HERE>
ACCESS_TOKEN_SECRET=<YOUR_ACCESS_TOKEN_SECRET_HERE>
CONSUMER_KEY=<YOUR_CONSUMER_KEY_HERE>
CONSUMER_SECRET=<YOUR_CONSUMER_SECRET_HERE>
- Make changes in the logic of the bot by modyifing
src/bot.py
- Test your changes locally by running
python src/bot.py
from the root directory of your project
Running on Local Machine with Docker Compose
You can also run the application in a docker container using docker compose(if you have it installed)
- Clone the repository:
git clone https://github.com/Nneji123/RapLyricsBot.git
- Change the directory:
cd RapLyricsBot
-
Edit the
.envexample
file and store your keys there. -
Run the docker compose command
docker compose up -d --build
And then the lyrics should be tweeted.
Running in a Gitpod Cloud Environment
Click the button below to start a new development environment:
Test Bot
To test the API functions do the following:
- Clone the repository:
git clone https://github.com/Nneji123/RapLyricsBot.git
- Change the working directory and install the requirements and pytest:
cd Raplyricsbot
pip install -r requirements.txt
- Move to the tests folder and run the tests
pip install pytest
pytest tests
- Add more lyrics
- Change this from a Rap lyrics bot to a general rap bot
- Get more lyrics using this library https://github.com/johnwmillr/LyricsGenius
- Update Readme.
- Update tests