Where Should I Go Eat? About The Web App

Where Should I Go Eat? About The Web App

I wrote a web app a few years back, at least, called Where Should I Go Eat?. You can visit it here. This post explains my inspiration behind the app and what language it’s written in.

My Inspiration For Where Should I Go Eat?

I used to work for Twitter in their Atlanta, GA data center. My job was to fix the broken servers running the platform. It was a cool job but I left in December 2020 to become an entrepreneur.

I bring this up because every Friday Twitter would purchase us lunch. We had a budget of $19 per person. Most of the employees would order lunch together from a specific restaurant using DoorDash while others went out to eat. Either way there was always a big discussion about where to eat lunch. And these discussions would always start early every Friday.

That’s because my coworkers couldn’t come to an agreement about where to go. Some may want to eat at a Thai restaurant. Others wanted Chick-fil-A. I had no problem eating from Chipotle as I was a major fan of the restaurant at the time. All this back and forth got me thinking one day: I could make a program that randomly determines which place we should go eat.

Just like my other web app, Black History Facts Generator, I created the app while teaching myself the Python programming language. The first version allow visitors to pick where to eat based on a budget. I scrapped that in the next version to allow visitors to get a totally random restaurant choice by clicking a button. However, if they wanted a local, non-chain restaurant I gave them the option to click a button that opens Google Map to show local restaurants in their area.

Programming Languages Used In The Site

I originally used Python and Flask in the web app and I still do till this day. You can view the code in my Github repo here. Or you can view the main bit of code tying everything together below:

@app.route("/")
def blank():
    """
    :return: The function returns the blank index.html website without a restaurant chosen. It is also used to
    clear the website of any choices if the reset button is clicked.
    """
    return render_template("index.html")


@app.route("/", methods=["GET", "POST"])
def main():
    """
    This function opens and read the restaurant.txt file which is located in the /static/files directory.
    Then a loop runs over the entire file, reading each line. The loop collects all the lines as a list, and then pulls
    out a restaurant randomly using the random.choice function.
    :return: The function returns a random restaurant to the index.html template, which displays it
    on the website.
    """
    with open("static/files/restaurant.txt", "r") as restaurant:
        restaurant_list = restaurant.readlines()
    return render_template("index.html", restaurant=random.choice(restaurant_list))

However, I created a version using JavaScript and Node/Express/EJS when I taught myself JavaScript and Node/Express/EJS throughout 2021. Just like the Python/Flask version you can view the full code on its Github repo here. Again, I provide the main bit of code running the site below:

app.get("/", (req, res) => {
  // Both variables are blank so when the user loads up the website it's blank and waiting for them to click the button.
  var randomRestaurant = "";
  var restaurantResult = "";

  res.render("index", {randomRestaurant, restaurantResult});
});

app.post("/", (req, res) => {
  // Now the variables hold the code so once the user clicks the button the code picks the random restaurant.
  var randomRestaurant = restaurant.getRestaurant()[Math.floor(Math.random() * restaurant.getRestaurant().length)];
  var restaurantResult = randomRestaurant;

  res.render("index", {randomRestaurant, restaurantResult});
});

I use Heroku to deploy my web apps now after using PythonAnywhere for years. I recommend both for anyone wanting to deploy their web apps.


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