This project is the result of a challenge from days 59-60 in the TalkPython #100DaysOfCode course.
The lesson focuses on learning to use the Python Tweepy
module to interact with the Twitter API and the course suggests a number of challenges to get practice with the lesson content, listed at the end of this Jupyter Notebook. I wanted to learn to build a full-fledged application, so I chose to follow the example in the RealPython article: Building a web app with Bottle, SQLAlchemy, and the Twitter API.
Over roughly two months, my version of the application gave me extensive practice with topics like:
- Classes, including class inheritance.
- GitHub Actions
pytest
Tweepy
PostgreSQL
- PGAdmin
SQLAlchemy
- Containerized applications with Docker
- Docker Compose
- Clean code writing using Better Code Hub
bottle
- Visual Studio Code development containers
- Docker Compose
I successfully built an application that:
- Uses Tweepy
to retrieve a set tweets for the wwt_inc Twitter account.
- Extract hashtags from the set of tweets.
- Builds database tables in a PostgreSQL database for tweets and hashtags using SQLAlchemy
.
- Loads tweets and hashtags into the database.
- Write pytest
tests that mock several Tweepy
and SQLAlchemy
objects/classes.
- Read tweets and hashtags from the database, optionally filtering data.
- Display tweets and hashtags with a bottle
hosted web application.
My application uses Docker Compose to build the following components:
- 1 x PostgreSQL container.
- 1 x Pgadmin container.
- 1 x Application container for Python applications that interact with Twitter and PostgreSQL, plus serve a web application with bottle
.
- 1 x Docker network with auto-DNS.
- 1 x Docker persistent volume for database storage.
- Several local volume mounts for container code consumption and Pgadmin configuration storage.
To give the application a try for yourself, I recommend the following setup steps:
-
Clone this repository to an environment with Docker and Docker Compose runtime environments, plus an Internet connection.
-
Use your shell prompt to navigate to the cloned repository.
-
Create the following .env files and populate the variable values with the appropriate information:
# ./app/.env APP_DB_USER=db_user APP_DB_PASS= APP_LOCATION=local POSTGRES_USER=root POSTGRES_PASSWORD= DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/ww_tweeter DB_TEST_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/ww_tweeter_test TWITTER_KEY= TWITTER_SECRET= TWITTER_ACCESS_TOKEN= TWITTER_ACCESS_SECRET=
# ./dockerfiles/db/.env APP_DB_USER=db_user APP_DB_PASS= POSTGRES_USER=root POSTGRES_PASSWORD=
# ./dockerfiles/db_admin/.env PGADMIN_DEFAULT_EMAIL=user@dbadmin.com PGADMIN_DEFAULT_PASSWORD=
-
Enter the following command in your shell:
docker compose up -d
-
Wait a few minutes for the images to build and for the containers to start.
-
Attach to the application container with the following command:
docker exec -it ww-tweeter-app-1 /bin/bash
-
Start the Python application with the following command:
./app/tweeter/ww_tweeter.py
-
Navigate to the web application with a browser.
Take note that this application is built for learning, development, and testing, so the Python application does not automatically start (via the Dockerfile CMD
or ENTRYPOINT
instructions) and SQLAlchemy
and bottle
debugging are active.