# Project export: SmartPlate

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 10.0
- Tagline: Find a personalized recipe, based on your allergy, time, and ingredient preferences.
- Devpost: https://devpost.com/software/smartplate-f2vsy5
- GitHub: https://github.com/alinaxrs/CalHacks
- Team: 3 GitHub contributor(s) — Rithwik Garapati (2 commits), alinaxrs (2 commits), Hanshal Dabbiru (1 commits)

## Devpost submission (written by the team)

### Inspiration

As college students new to the apartment life, we've spent lots of time trying to figure out the best recipes that we can cook, based on the ingredients that we currently have. We built this website to make the process of cooking meals easier and more streamlined.

### What it does

You can input your preferences about allergies, prep time, and the ingredient you want to be featured the most in your recipe. Our website will search through a database of recipes and find the recipe most tailored to your needs.

### How we built it

We used HTML and CSS for our front end on Microsoft VS Code, and used node.js for our backend server. We also used sqlite to store our database of recipes as well as to query the data.

### Challenges we ran into

It was difficult for us to send and retrieve HTML data from ports using node.js.

### What we learned

We learned a lot of new technologies as we experimented with what path we wanted to take when approaching the construction of this project.

## README (from the GitHub repository)

# CalHacks


## Detected evidence (automated analysis)

Indexed codebase: 8 recognized source files, 8 KB.
- CSS (language) — detected in the code
- HTML (language) — detected in the code
- JavaScript (language) — detected in the code
- Express (technology) — claimed on Devpost, not found in the code
- Node.js (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (8 of 8)

```
index.html
myfirst.js
myfirstmodule.js
README.md
search_page/index.html
search_page/script.js
search_page/styles.css
styles.css
```

### Dependencies

No dependency index available.

### Recent commits (newest first)

- Update README.md
- completed project
- added styles to second page
- Added html and some styling to search page
- frontend homepage done
- Initial commit

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

### myfirstmodule.js

```javascript
exports.myDateTime = function() {
    return Date();
}
```

### index.html

```html
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Recipe Generator</title>
    <link rel="stylesheet" href="styles.css">

</head>
<body>
    <div id="home">
        <div id="left">
            <img src="images/food.jpg" alt="food image">
        </div>
        <div id="right">
            <h1 id="heading1">smart plate</h1>
            <div id="mission">
                <p id="missionpara">your guide to choosing recipes, tailored to you.</p>
            </div>
            <button id="search">start your search!</button>
            <script>
                function redirectToNewPage() {
                    var newPageUrl = "search_page/index.html"
                    window.location.href = newPageUrl;
                }
                var button = document.getElementById('search');
                button.onclick = redirectToNewPage;
            </script>  
            
        </div>
    </div>
</body>
</html>
```

### styles.css

```css
#home{
    display: flex;
    justify-content: space-evenly;
    background-color: aliceblue;
}

#left img{
    display: block;
    width: 600px;
    height: 600px;
    border-radius: 10px;
    margin: 40px 40px;
}

#right{
    display: block;
    margin-top: 200px;
}

#heading1{
    color: #D05438;
    text-align: center;
    font-size: 80px;
    font-family: 'Trebuchet MS', Arial, sans-serif;
    font-style: normal;
    font-weight: 400;
    line-height: 100%; /* 120px */
    letter-spacing: -3.6px;
    margin-bottom: 20px;
    display: block;
}

#mission{
    display: block;
    margin-left: 60px;
    margin-right: 60px;

}

#missionpara{
    color: #8C3825;
    text-align: center;
    font-family: 'Trebuchet MS', Arial, sans-serif;
    font-size: 25px;
    font-style: normal;
    font-weight: 400;
    line-height: 100%;
    letter-spacing: -0.75px;
    display: block;

    
}

#search{
    width: 354px;
    height: 71px;
    flex-shrink: 0;
    border-radius: 20px;
    background: #8C3825;
    display: block;
    color: #FFF;
    font-family: 'Trebuchet MS', Arial, sans-serif;
    font-size: 25px;
    font-style: normal;
    font-weight: 400;
    margin-left: auto;
    margin-right: auto;
    border-width: 0px;
}

#results {
    border: 1px solid;
  }

```

### myfirst.js

```javascript
let https = require('http');
let url = require('url')
const sqlite3 = require('sqlite3').verbose();
const express = require('express');
const app = express();
let fs = require('fs');
const cheerio = require('cheerio');
const { text } = require('body-parser');
//import * as cherio from 'cheerio';

//const controller = new AbortController();
//let wss = new require('ws').server;({server: server});

let db = new sqlite3.Database('C:\\sqlite3\\recipes.db', sqlite3.OPEN_READONLY, (err) => {
    if(err) {
        return console.error(err.message);
    }
    console.log('Connected to the SQLite database');
});

let results = [];


let server = https.createServer(async function (req, res) {
    server.on('request', app);

    var q = url.parse(req.url, true);
    var data = q.query;
    let sql = 'SELECT name FROM recipes WHERE minutes = ' + data.time;
    db.serialize(() => {
        db.each(sql, (err, row) => {
            if(err) {
                console.log(err.message);
            }
           // console.log(row);
            results.push(row.name);
        });
    });

    // const $ = await cheerio.fromURL('search_page/index.html');
    // $('ul').append('<li>xyzz</li>');


    // Putting results into the html file.
    fs.readFile('./search_page/index.html', 'utf8', function(err, data){
        var $ = cheerio.load(data);
        //const mylist=document.getElementById("mylist");
        for(let i = 0; i < 5; i++)
        {
            // let recipeName = results[i].name;
            // let node = document.createElement("li");
            // let textnode = document.createTextNode(recipeName);
            // node.appendChild(textnode);
            // mylist.appendChild(node);
            console.log($('ul'));
            $('ul').append('<li>' + results[i] + '</li>');
            console.log(results[i]);

        }
        console.log($);
        
    });
    //res.write(JSON.stringify(results));

    res.end();
});
server.listen(8080);
server.close();

/*app.get('/', (req, res)=>{
    // for(let i = 0; i < 5; i++)
    // {
    //     res.send(results[i].name);
    // }
    res.send("Hello World");
    //res.send("results");
});*/


server.listen(8080);

function buildHTML(req)
{

}


var myEventHandler = function() {
    console.log("I HEAR A SCREAM!");
}

/*
eventEmitter.on('scream', myEventHandler);
eventEmitter.emit('scream')
*/

/*db.close((err) => {
    if(err) {
        return console.error(err.message);
    }
    console.log('Close the database connection');
})*/
```

### search_page/script.js

```javascript
function sendRecipes()
 {
    fetch("http://127.0.0.1:5500/search_page/index.html").then(res => res.json()).then(response => {
        
        
    })
 }
```

### search_page/styles.css

```css
body{
    width: 99%;
    height: 100%;
    background-color: aliceblue;
}

#header{
    display: block;
    text-align: center;
    background-image: url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQYPWW9zog62tzZXbg7M08lGPmysQ5_hsDk7NWAW-CAV4rLrF80yW2IAizjMv98T-5OWXk&usqp=CAU');
    background-color: #dcefff;
    background-blend-mode: multiply;
    padding: 1px;
}

#heading-div{
    display: block;
    /*backdrop-filter: blur(7px);*/
    background-color: aliceblue;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    padding-left: 15px;
    padding-right: 15px;
    border-radius: 10px;
}

#heading{
    color: #D05438;
    font-family: 'Trebuchet MS', Arial, sans-serif;
    font-weight: 400;
    letter-spacing: -2px;
    font-size: 80px;
}

#textinstructions{
    display: block;
    color: #8c3825;
    margin-top: 30px;
    font-family: 'Trebuchet MS', Arial, sans-serif;
}

#overview{
    text-align: center;
    font-size: 35px;
}

#instruction{
    font-size: 20px;
    text-align: center;
    margin-bottom: 18px;
}

#all_inputs{
    display: flex;
    justify-content: space-around;
}

.input_box{
    margin: 0 15px;

}

#find{
    border-radius: 20px;
    background: #8C3825;
    display: block;
    color:aliceblue;
    font-family: 'Trebuchet MS', Arial, sans-serif;
    font-size: 20px;
    margin-left: auto;
    margin-right: auto;
    border: #8C3825;
    margin-top: 10px;
    padding: 10px;
}
```

### search_page/index.html

```html
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Search Page</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div id="header">
        <div id="heading-div">
            <h1 id="heading">smart plate</h1>
        </div> 
    </div>
    <div class = "focus", id="textinstructions">
        <h3 id="overview">find a personalized recipe, based on your selected preferences</h3>
        <h5 id="instruction">select your preferences!</h5>
    </div>


    <iframe name="dummyframe" id="dummyframe" style="display: none;"></iframe>

    <div id="all_inputs">
        <form action="http://localhost:8080" method="GET" target="dummyframe">
            <input class="input_box" type="text" name = "allergies" style="font-size: 20;" placeholder="allergies">
            <input class="input_box" type="text" name = "time" style="font-size: 20;" placeholder="prep time">
            <input class="input_box" type="text" name = "ingredient" style="font-size: 20;" placeholder="star ingredient">
            <button id = "find" type="submit">find!</button>
        </form>
    </div>
    <ul id="mylist">
        <h4>Recipes</h4>
        <li>xyz</li>
    </ul>


    <div>
        <!-- <table id = "results">
        <span><label>name </label></span>
        <span><label>minutes </label></span>
        <span><label>n_steps </label></span>
        <span><label>steps </label></span>
        <span><label>description </label></span>
        <span><label>ingredients </label></span>
        <span><label>n_ingredients </label></span>
        </table> -->
    </div>
</body>
</html>
```