-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbestRpiDininghall.html
More file actions
243 lines (204 loc) · 6.16 KB
/
bestRpiDininghall.html
File metadata and controls
243 lines (204 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>RPI Dining Hall Menu Extractor</title>
<style>
body {
font-family: "Segoe UI", Tahoma, sans-serif;
margin: 0;
padding: 40px 20px;
background: #eef1f5;
color: #2b2b2b;
display: flex;
justify-content: center;
}
.container {
max-width: 900px;
width: 100%;
background: #ffffff;
padding: 35px 40px;
border-radius: 14px;
box-shadow: 0 6px 30px rgba(0, 0, 0, 0.08);
}
h1 {
margin-top: 0;
font-size: 28px;
font-weight: 700;
color: #1f3c88;
}
p {
font-size: 15px;
background: #f5f8ff;
padding: 12px 15px;
border-radius: 10px;
border-left: 4px solid #1f3c88;
color: #3e4c68;
}
button {
background: #1f7a54;
color: white;
border: none;
padding: 12px 18px;
font-size: 16px;
font-weight: 600;
border-radius: 8px;
cursor: pointer;
transition: 0.25s;
}
button:hover {
background: #146544;
transform: translateY(-2px);
}
#output {
margin-top: 22px;
padding: 20px;
background: #fafafa;
border: 1px solid #d9d9d9;
border-radius: 10px;
font-family: Consolas, monospace;
font-size: 14px;
max-height: 550px;
overflow-y: auto;
white-space: pre-wrap;
}
.copy-btn {
background: #2764c5;
margin-top: 16px;
display: inline-block;
padding: 10px 16px;
border-radius: 8px;
color: white;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: 0.2s;
}
.copy-btn:hover {
background: #1e4e9e;
transform: translateY(-1px);
}
.copy-btn.copied {
background: #1f7a54;
}
.error {
margin-top: 16px;
padding: 14px;
background: #ffecec;
color: #c0392b;
border-left: 4px solid #c0392b;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="container">
<h1>RPI Dining Hall Menu Extractor</h1>
<p>
Extracts only: <code>name, calories, protein, allergens, isVegan</code>.<br>
<strong>Automatically filters out:</strong> Bakery, Dessert, Beverages, Bliss.
</p>
<button id="fetchBtn">Fetch All Dining Hall Menus</button>
<div id="output">Awaiting action...</div>
</div>
<script>
const API_KEY = "68717828-b754-420d-9488-4c37cb7d7ef7";
const diningData = [
{ name: "BARH", location_id: "76929003", menu_id: "153626" },
{ name: "Commons", location_id: "76929001", menu_id: "153148" },
{ name: "Russell Sage", location_id: "76929002", menu_id: "153157" },
{ name: "Blitman", location_id: "76929015", menu_id: "153702" }
];
const EXCLUDED_GROUPS = ["Bakery", "Dessert", "Beverages", "Bliss"];
function extractItem(item) {
return {
name: item.formalName,
calories: item.calories || null,
protein: item.protein ? `${item.protein}g` : null,
allergens: item.allergens ? item.allergens.map(a => a.name) : [],
isVegan: !!item.isVegan
};
}
function buildFilteredJson(data) {
const result = {};
const meals = Array.isArray(data) ? data : data.meals || [];
meals.forEach(meal => {
const mealName = meal.name;
result[mealName] = {};
meal.groups.forEach(group => {
if (EXCLUDED_GROUPS.includes(group.name)) return;
result[mealName][group.name] = group.items.map(extractItem);
});
});
return result;
}
async function callGemini(promptText) {
try {
const response = await fetch("https://bytebite-615j.onrender.com/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt: promptText })
});
const data = await response.json();
if (data.text) {
alert("AI Ranking Result:\n\n" + data.text);
} else if (data.error) {
console.error("Gemini API error:", data.error);
}
} catch (err) {
console.error("Fetch failed:", err);
}
}
async function copyCompactJson(data) {
const compact = JSON.stringify(data, null, 0);
console.log("CALLING GEMINI");
await callGemini(
"Rank RPI dining halls for muscle gain and lactose intolerance. Total=100%. For each hall, output exactly:"+
"Hall: X%\n"+
"Top3: food1, food2, food3\n"+
"Data: " + compact
); console.log("success:");
}
document.getElementById("fetchBtn").addEventListener("click", async () => {
const output = document.getElementById("output");
output.textContent = "Fetching dining hall menus...";
const allMenus = {};
try {
for (const hall of diningData) {
const url = `https://api-prd.sodexomyway.net/v0.2/data/menu/${hall.location_id}/${hall.menu_id}?date=2025-11-21`;
const resp = await fetch(url, {
headers: {
"accept": "application/json",
"content-type": "application/json",
"api-key": API_KEY
}
});
if (!resp.ok) throw new Error(`HTTP ${resp.status} for ${hall.name}`);
const fullData = await resp.json();
allMenus[hall.name] = buildFilteredJson(fullData);
}
output.textContent = JSON.stringify(allMenus, null, 2);
const copyBtn = document.createElement("div");
copyBtn.textContent = "Copy & Rank with Gemini AI";
copyBtn.className = "copy-btn";
copyBtn.onclick = async () => {
await copyCompactJson(allMenus);
copyBtn.textContent = "Done!";
copyBtn.classList.add("copied");
setTimeout(() => {
copyBtn.textContent = "Copy & Rank with Gemini AI";
copyBtn.classList.remove("copied");
}, 2000);
};
output.appendChild(copyBtn);
} catch (err) {
output.innerHTML = `
<div class="error">
<strong>Error:</strong> ${err.message}<br>
<small>Network or API key issue.</small>
</div>`;
}
});
</script>
</body>
</html>