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
.envin 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.pyfrom 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
.envexamplefile 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
