Quick Black History Facts: An Introduction

One of my technical projects I updated several days ago upon the publication of this post is Quick Black History Facts (which you can visit here). In this post I will discuss the following topics about this web application:

  1. Why I created it
  2. The code running it
  3. My future plans for the web application

Why I Created Quick Black History Facts

The reason why I created this web application starts in 2018. That year I taught myself the Python programming language from a course on Udemy. Then in 2019 I improved my Python skills by creating more projects. One of those projects was Quick Black History Facts (which was formally called Black History Facts Generator). February was fast-approaching and it was time again for me to celebrate Black History Month.

During that month I would tweet random facts on my Twitter account, but that’s time-consuming. This manual process is perfect for a computer program, and I thought about creating one to connect to the Twitter API. That way the random fact would tweet out automatically. Thus, I started devisinig my plan.

The Plan’s Objective Changes

As I worked on this project further, the objective of what I wanted to accomplish changed. It changed because my programming skill-set to use the Twitter API was not strong enough. Frankly, I was out of my depth. So I pivoted to building a website to display the facts because I was familiar in website design.

The Front-End Coding Running Quick Black History Facts

I used Bootstrap to build out the Front-End of the website because of the following reasons:

  • Ease to use
  • Rich responsive website design features
  • Offers good performance

In addition to Bootstrap I use regular (or vanilla) HTML and CSS to build out the Front-End.

The Back-End Coding Running Quick Black History Facts

I used Python and Flask to build out the Back-end of the website. I chose to use Flask over Django because it requires much less code to spin up a simple application.

The Python code to display the ranom fact on the screen is in these three lines of code:

with open("static/files/black_history_facts.txt", "r") as facts:
    fact_list = facts.readlines()
return render_template('index.html', black_history_fact=random.choice(fact_list))

Let’s go through the code line by line:

  1. All the facts are in a text file delimited with a newline at the end of each sentence.
  2. Using “with open” to open that file as read-only and read the contents using a loop.
  3. The loop iterates over each individual line in the text file with the “readlines” Python built-in function.
  4. A list stores each individual fact.
  5. Using Flask’s “render_template” function and Python’s built-in function “random.choice” a random fact from the list displays on the screen.

My Future Plans For This Application

I don’t have any major plans to modify the code for Quick Black History Facts. My only plan is to add more Black History facts to the text file.