Brittbot

Upgrading from Data Center Tech to Software Engineer

A fast food restaurant on a sunny afternoon with vehicles parked in the parking lot attached to the restaurant. Above the restaurant is a sign with the phrase: Where Should I Go Eat

Where Should I Go Eat: An Introduction

The last of my technical projects I haven’t talked about yet is Where Should I Go Eat (which you can visit here). In this post I will discuss the following topics about this web application:

  • Why I created it
  • The code running it
  • My future plans for the web application

Why I Created Where Should I Go Eat

This story is similar to my story for creating Black History Fact Generator: The year was 2019. I worked at Twitter as a Site Operations Technician at the Atlanta, GA data center. The year prior I taught myself the Python programming language using an Udemy course, and I found myself wanting to create more projects to increase that skill.

Since I worked at the data center and not an actual Twitter office, the company provided a catered Monday through Thursday. Every Friday we had the opportunity to spend our daily lunch budget ($19 at the time) on our own. We could order lunch via Doordash or go out to eat. Usually, we chose the former because lunchtime traffic in Downtown Atlanta sucks.

My team always fought about which restaurant to order from. Some people wanted fast food like Chick-fil-A. Others wanted to eat from the newest hip restaurant. We would argue back and forth in the Slack channel dedicated to our lunch order.

One day I made a joke that I should build an app that chose a restaurant at random for us. That got a few laughs, and one of the Site Reliability Engineers (SREs) on my team told me to do just that. He knew I taught myself Python and that project would get me to flex those skills. So that’s what I did.

I brainstormed names for my app, decided on Where Should I Go Eat, and bought a domain name from Namecheap.

The Code Running Where Should I Go Eat

All the code can be found on the project’s GitHub repo.

Front-End Code

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.

Back-End Code

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 randomly choose a restaurant is in the main.py file. I’ll include a snippet of that file below:

with open("static/files/restaurants.txt", "r") as restaurants:
        restaurant_list: [str] = restaurants.readlines()

    # Choose a random restaurant
    random_restaurant: [str] = random.choice(restaurant_list)

    # Strip the newline character from the end so the search is successful
    random_restaurant: [str] = random_restaurant.strip()

    # Initializing variable
    found_restaurant_url: str = ""

    # Search the nested tuples for the correct restaurant URLs matching the chosen random restaurant
    for restaurant in restaurant_urls:
        if random_restaurant in restaurant:
            found_restaurant_url: str = restaurant[1]

Let’s go through the code line by line:

  1. I have all the restaurants in a text file called restaurants.txt. Using the “with open” command I read all the names into a list called “restaurant_list.”
  2. Then I use the “random.choice” function to choose a random restaurant from the “restaurant_list” list.
  3. After that I strip the newline character from the end of the “random_restaurant” so when I search for it, the exact match appears.
  4. I initialize a variable to hold the “random_restaurant” URL.
  5. Finally, I use a “for” loop to search through the tuple containing the restaurants and their URLs in the “restaurants_urls.py” file, and assign the one matching the “random_restaurant.”

The main.py file contains all the route (or links) to the home page, which displays the random restaurant and its URL.

I include the restaurant on the home page template as so:

<div class="col">
            <button class="button" name="start-over" type="submit" onclick="location.href=location.href">Reset</button>
        </div>
        <p class="restaurant-result">You Should
            Go Eat At {{ restaurant }}</p>
        <p class="restaurant-link">Order Online At {{ restaurant }} <a href="{{ restaurant_link }}"
                                                                       target="_blank">here</a></p>
    </div>
</div>

If users wants to generate another random restaurant they click the button on screen, which runs the function again.

My Future Plans For This Application

I had some plans to use geolocation to provide restaurants available in that visitor’s location, but I haven’t worked on that feature. I may in the future.