# Project export: What2Eat

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: Cal Hacks 11.0
- Tagline: Planning group meals can be a headache with everyone's different preferences. What2Eat solves that with a single click, finding a restaurant everyone will love!
- Devpost: https://devpost.com/software/what2eat-octx2b
- GitHub: https://github.com/Cookei/calhacks11.0
- Demo: https://www.canva.com/design/DAGUIY55D4o/Q5joXTC0f_Lyt0bElzF5Og/edit
- Team: 3 GitHub contributor(s) — Cookie (18 commits), Olivia Xie (9 commits), jackiedai (4 commits)

## Devpost submission (written by the team)

### Overview

what2eat is an event-planning website inspired by the simplicity of when2meet.com and realized by the need for efficient eating socials. As busy college students with friends who often have conflicting tastes, we built this web app to take the guesswork out of finding the most suitable restaurants.

## README (from the GitHub repository)

# calhacks11.0

## Detected evidence (automated analysis)

Indexed codebase: 21 recognized source files, 42 KB.
- CSS (language) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code
- Firebase (technology) — claimed on Devpost, not found in the code
- Flask (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (26 of 26)

```
README.md
what2eat/.gitignore
what2eat/backend/.flaskenv
what2eat/backend/get_yelp.py
what2eat/backend/keys.py
what2eat/backend/main.py
what2eat/package.json
what2eat/public/index.html
what2eat/public/manifest.json
what2eat/public/robots.txt
what2eat/README.md
what2eat/src/App.css
what2eat/src/App.js
what2eat/src/App.test.js
what2eat/src/components/Dropdowns.js
what2eat/src/components/Listing.js
what2eat/src/components/ListingContainer.js
what2eat/src/components/Navbar.js
what2eat/src/components/NumberInput.js
what2eat/src/components/PageButton.js
what2eat/src/index.css
what2eat/src/index.js
what2eat/src/pages/Input.js
what2eat/src/pages/Landing.js
what2eat/src/reportWebVitals.js
what2eat/src/setupTests.js
```

### Dependencies

- what2eat/package.json: @testing-library/jest-dom@^5.17.0, @testing-library/react@^13.4.0, @testing-library/user-event@^13.5.0, react@^18.3.1, react-dom@^18.3.1, react-google-autocomplete@^2.7.3, react-scripts@5.0.1, web-vitals@^2.1.4, wouter@^3.3.5

### Recent commits (newest first)

- Merge branch 'main' of https://github.com/Cookei/calhacks11.0
- Final
- Merge branch 'main' of https://github.com/Cookei/calhacks11.0
- add jamaican and change colors
- input fixed
- fix pref ui
- Merge branch 'main' of https://github.com/Cookei/calhacks11.0
- Update Input.js
- resolve merge
- implement restaurant route
- results
- Input page
- Merge branch 'main' of https://github.com/Cookei/calhacks11.0
- add listing container
- button scale hover fix
- Merge branch 'main' of https://github.com/Cookei/calhacks11.0
- input form css
- add listing container
- Merge branch 'main' of https://github.com/Cookei/calhacks11.0
- input and api changes

## Key source files (fetched from GitHub, selected and truncated for size)

### what2eat/package.json

```
{
  "name": "what2eat",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://127.0.0.1:5000/",
  "dependencies": {
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-google-autocomplete": "^2.7.3",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4",
    "wouter": "^3.3.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

```

### what2eat/src/index.js

```javascript
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

```

### what2eat/src/App.js

```javascript
import "./App.css";

import { Redirect, Route, Switch } from "wouter";
import Landing from "./pages/Landing";
import Navbar from "./components/Navbar";
import Listing from "./components/Listing";
import Input from "./pages/Input";
import ListingContainer from "./components/ListingContainer";

function App() {
  return (
    <div style={{ position: "relative" }}>
      <svg
        style={{
          zIndex: "1",
          position: "fixed",
          left: 0,
        }}
        width="1437"
        height="628"
        viewBox="0 0 1437 628"
        fill="none"
        xmlns="http://www.w3.org/2000/svg"
      >
        <path
          d="M406.5 314C311 314 156 356 0.5 278.5V628H1437V-3.05176e-05C1374 -2.57492e-05 1225.5 10.7994 1137.5 24.5C1049.5 38.2006 820 144.5 731.5 201C643 257.5 502 314 406.5 314Z"
          fill="#FAD5A2"
        />
      </svg>
      <div style={{ zIndex: "10", position: "relative" }}>
        <Navbar />
        <Switch>
          <Route path="/">
            <Landing />
          </Route>
          <Route path="/event">
            <Input />
          </Route>
          <Route path="/test">
            <ListingContainer />
          </Route>
          <Route path="*">
            <Redirect to="/" />
          </Route>
        </Switch>
      </div>
    </div>
  );
}

export default App;

```

### what2eat/backend/main.py

```python
from flask import Flask, jsonify, request
from get_yelp import get_details, average_distance, average_price
import json
import requests

app = Flask(__name__)


@app.route("/")
def home():
    return "Hello World"


# create new url instance
# required arguments
# num-participants: int
@app.route("/create-new-event", methods=["POST"])
def get_preferences():
    if request != None:
        print(request.json)


# submit preference data for one participant
@app.route("/submit-form", methods=["POST"])
def submit_form():
    if request != None:
        print(request.json)


# return recommended restaurants
# if everyone has submitted the form -> return remaining
# else -> return recommended restaurants
@app.route("/restaurants", methods=["POST"])
def recommend_restaurants():
    if request != None:
        data = request.json
        lon = data["location"][1]
        lat = data["location"][0]
        price = average_price(data["preferredPrice"])
        cuisines = set(data["preferredCuisines"])
        yelp_response = get_details(lon, lat, cuisines, price)
        print(yelp_response)
        print(cuisines)
        return jsonify(format_restaurant_details(yelp_response))
    else:
        return jsonify({"message": "no request found"}), 400


# average_price(data["preferredDistance"])
def format_restaurant_details(yelp_details):
    max = 3
    restaurants = []

    for i, bus in enumerate(yelp_details.get("businesses")):
        if i >= 3:
            break
        restaurants.append(
            restaurant(
                name=bus["name"],
                distance=bus["distance"],
                rating=bus["rating"],
                price=bus["price"],
                webpage=bus["url"],
                icon=bus["image_url"],
                cuisines=bus["categories"][0]["title"],
            )
        )
    return restaurants


def restaurant(name, distance, rating, price, webpage, icon, cuisines):
    data = {
        "name": name,
        "icon": icon,
        "price": price,
        "website": "https://" + webpage,
        "distance": distance,
        "rating": rating,
        "cuisines": cuisines,
    }
    return json.dumps(data, indent=4)


# firebase stuff

# import modules
import firebase_admin
from firebase_admin import db, credentials

# authenticate to firebase
cred = credentials.Certificate("credentials.json")
firebase_admin.initialize_app(
    cred, {"databaseURL": "https://what2eat-joha888-default-rtdb.firebaseio.com/"}
)

# create ref to root node
ref = db.reference("/")


# store an event as a firebase node upon "create event" action
@app.route("/create", methods=["POST"])
def create_event():
    # store eventObj
    event_ref = ref.child("create")
    new_event_ref = event_ref.push(request.json)

    postID = new_event_ref.key
    print("key", postID)

    return str(postID)


# store a preference object as a child under create/prefs
@app.route("/setprefs", methods=["POST"])
def set_prefs():

    # locate the specific key
    data = request.json
    key = data["key"]
    prefs = data["preferences"]
    pref_ref = ref.child("create/" + str(key) + "/prefs")  # access the specific event

    pref_ref = pref_ref.push(prefs)  # push preferences as a new node under /prefs

    postID = pref_ref.key
    print("key", postID)

    return str(postID)


# retrieve data given a specific event
@app.route("/retrieve", methods=["POST"])
def retrieve_event():

    key = request.json

    event_ref = ref.child("create/" + str(key))

    data = event_ref.get()

    print("data", data)

    return str(data)


@app.route("/checkKeyExists", methods=["POST"])
def checkKeyExists():
    key = request.json
    data = ref.child("create/" + str(key))
    print(data.get())
    return data.get()


if __name__ == "__main__":
    app.run(debug=True)

```

### what2eat/backend/keys.py

```python
YELP_API_KEY = "5Tiq5F0K_gF5UfLJ1APLZfiOXqqHuS7LqJMDEohAPa0aXFWxa6blef4tNqkH92Bf0ve1J1Tp9GM-RjsBOhUpylM5LYu0h84m0oaQc-ix8MoH8oeAUKlhL4pDYbIUZ3Yx"

```

### what2eat/src/setupTests.js

```javascript
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

```

### what2eat/src/App.test.js

```javascript
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
  render(<App />);
  const linkElement = screen.getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

```

### what2eat/src/reportWebVitals.js

```javascript
const reportWebVitals = onPerfEntry => {
  if (onPerfEntry && onPerfEntry instanceof Function) {
    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
      getCLS(onPerfEntry);
      getFID(onPerfEntry);
      getFCP(onPerfEntry);
      getLCP(onPerfEntry);
      getTTFB(onPerfEntry);
    });
  }
};

export default reportWebVitals;

```

### what2eat/src/index.css

```css
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
    monospace;
}

```

### what2eat/backend/get_yelp.py

```python
import requests
from keys import YELP_API_KEY


def average_distance(dist_array):
    """returns the average distnace of user inputted distances"""
    return sum(dist_array) / len(dist_array)


def average_price(dist_array):
    """returns the average distnace of user inputted distances"""
    return round(sum(dist_array) / len(dist_array))


def get_details(lat, long, fields, price_pref):
    """
    inputs: latitude, longitude, result of average_distance(dist_array), preferred_cuisine
    output: json of places with details

    result = name, rating, price, cuisine_type, url
    """
    url = "https://api.yelp.com/v3/businesses/search"
    querystring = {
        "latitude": lat,
        "longitude": long,
        "categories": fields,
        "price": price_pref,
    }
    payload = ""
    headers = {
        "User-Agent": "insomnia/10.1.0",
        "Authorization": "Bearer " + YELP_API_KEY,
    }
    response = requests.request(
        "GET", url, data=payload, headers=headers, params=querystring
    )
    return response.json()

```

[10 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]