a laptop showing compute code on its screen sitting on a table

Where Should I Go Eat? | Why I Built This Web App

One of the categories in the navigation panel of my website is My Web Apps. When someone hovers over it a menu drops down and shows three links. The third, and currently last, in the list is Where Should I Go Eat? Why did I create this site? And how did I do it? Continue reading to find out.

Why I Built 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 catered lunch to us 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.

While ordering lunch was easy, 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 agure back and forth in the Slack channel dedicated to lunch.

I said as a joke one day 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. FYI: I buy all my domain names from Namecheap, and I highly recommend them to anyone needing domain name registration or web hosting.

Then I worked on the tech stack to get the app up and running. Speaking of that it’s time to explain what tools and frameworks I chose for Where Should I Go Eat?.

How I Built Where Should I Go Eat?

For the frontend I chose Bootstrap because of its ease of use and its responsive design. For the backend I used Python and Flask. I chose Flask over Django because the former requires much less code to get a simple web app up and running. I have nothing against Django, and I need to take a course about it. However, I would like to learn more about Flask first.

Finally, I host my app on Google Cloud. I use to use Heroku, but the service killed its free tier a couple of years ago. The monthly amount to run the app was too expensive for me. Yes, I pay for Google Cloud, but my monthly bill is under $1.00. I know there are other free IaaS providers out there, but I didn’t want to end up moving providers again if that free tier disappeared.

GitHub Repo

I host all the code for my web app on the public GitHub repo here. Let’s go through it. Note: I’m currently redesigning this app so the code may change.

main.py

The main.py file connects to the database containing the URLs for each restaurant so it can provide the correct URL for the random restaurant so the users can order online. Note: I removed the spacing and formatting from the following code snippet:

# Create the database connection
db_connection = sqlite3.connect("static/files/restaurant_urls")

# Created the cursor
db_cursor = db_connection.cursor()

That process happens after the function reads the data from the text file hosting the restaurants, and randomly chooses one using a built-in function. Note: I removed the spacing and formatting from the following code snippet:

with open("static/files/restaurant.txt", "r") as restaurant:
restaurant_list = restaurant.readlines()

chosen_restaurant = random.choice(restaurant_list)

# Removed the newline character at the end of the variable so the database query is successful
chosen_restaurant = chosen_restaurant.strip() 

Finally, the function performs the query to get the restaurant URL, closes the database connection, and sends all the data to the index.html file. Note: I removed the spacing and formatting from the following code snippet:

db_cursor.execute("SELECT restaurant_url FROM restaurant_urls WHERE restaurant_name = ?", (chosen_restaurant,))
    search_restaurant_link = db_cursor.fetchone()[0]

# Close the database connection
db_connection.close()  

return render_template("index.html", restaurant=chosen_restaurant, restaurant_link=search_restaurant_link)

index.html

The index.html file displays the home page from the main.py file onto the website using Flask tags. Note: I removed the spacing and formatting from the following code snippet:

<div class="container restaurant-result-container">
<p class="restaurant-result">You should go eat at <span class="restaurant-result-color">{{ restaurant }}</span></p>
<p class="restaurant-link-text">Order <a class="restaurant-link" href="{{ restaurant_link }}" target="_blank">{{ restaurant }}</a> online for pickup or delivery</p>
</div>

Again, I’m currently redesigning this web app, and I hope to have the changes uploaded to the site by some time in March 2024.


0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x