Avatar

@tal

1 like16 public vals
Joined May 22, 2023
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
import { menuMonths } from "https://esm.town/v/tal/menuMonths";
// Code emulating the DOE code
export function currentDateValues(): {
schoolYear: `${number}-${number}`;
month: string;
} {
const menuDate = new Date();
const actualYear = menuDate.getFullYear();
const currentMonth = menuMonths[menuDate.getMonth()];
let schoolYear: `${number}-${number}`;
if (
currentMonth === "September" || currentMonth === "October" ||
currentMonth === "November" || currentMonth === "December"
) {
schoolYear = `${actualYear}-${actualYear + 1}`;
}
else {
schoolYear = `${actualYear - 1}-${actualYear}`;
}
return {
schoolYear,
month: currentMonth,
};
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export const menuMonths = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
] as const;
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
// set at Mon Oct 23 2023 16:31:55 GMT+0000 (Coordinated Universal Time)
export let doeMenuResponseStore = {
"2023-2024|September|pre-k---8-express-hot-lunch-menu": {
"lastFetchedAt": "2023-09-30T23:10:59.401Z",
"lines": [{
"dateStr": "Date",
"date": { "type": "header" },
"menuStr": "Menu",
"menu": { "items": ["en"] },
}, {
"dateStr": "Daily Offerings",
"date": { "type": "Daily Offerings" },
"menuStr":
"{Daily Lunch Specials|Peanut Butter & Jelly (VE)|Cheese Sandwich (V)|Hummus Grab & Go (V)|1% Low Fat Milk (V)|Fat Free Milk (V)|Fat Free Chocolate Milk (V)|Condiments: Ketchup (VE)/ Mustard (VE)/ Mayonnaise (V)/ BBQ (VE) and Hot Sauce (V)|Fresh Fr
"menu": {
"items": [
"Daily Lunch Specials",
"Peanut Butter & Jelly (VE)",
"Cheese Sandwich (V)",
"Hummus Grab & Go (V)",
"1% Low Fat Milk (V)",
"Fat Free Milk (V)",
"Fat Free Chocolate Milk (V)",
"Condiments: Ketchup (VE)/ Mustard (VE)/ Mayonnaise (V)/ BBQ (VE) and Hot Sauce (V)",
"Fresh Fruit (VE)",
"Dressings: Chipolte Ranch (V)/ Balsamic Vinaigrette (V)/ Ranch (V)/ Asian Sesame (VE)/ Honey Mustard (V)/ Caesar/ French (V)/ Italian Vinaigrette (V)",
"Flavor Station: Granulated Garlic (VE)/ Red Pepper Flakes (VE)/ Parmesan Cheese (V)",
"Options may vary by location",
],
},
}, {
"dateStr": "September 1; 2023?Friday ",
"date": {
"type": "date",
"date": "2023-09-01T00:00:00.000Z",
"prefix": "September 1; 2023",
"suffix": "Friday ",
},
"menuStr":
"{Kidney Bean Rajma (VE)|served with Naan (VE)|Crispy Broccoli (V)|Three Cheese Grilled Cheese (V)|
"menu": {
"items": [
"Kidney Bean Rajma (VE)",
"served with Naan (VE)",
"Crispy Broccoli (V)",
"Three Cheese Grilled Cheese (V)",
" Heart Shaped Pretzels (VE)",
],
},
}, {
"dateStr": "September 4; 2023?Monday (Labor Day)",
"date": {
"type": "date",
"date": "2023-09-04T00:00:00.000Z",
"prefix": "September 4; 2023",
"suffix": "Monday (Labor Day)",
},
"menuStr":
"{Sicilian Slice Pizza (V) ||Roasted Zucchini (VE)}",
"menu": {
"items": [
"Sicilian Slice Pizza (V) ",
"",
"Roasted Zucchini (VE)",
],
},
}, {
"dateStr": "September 5; 2023?Tuesday ",
"date": {
"type": "date",
"date": "2023-09-05T00:00:00.000Z",
"prefix": "September 5; 2023",
"suffix": "Tuesday ",
},
"menuStr":
"{Turkey Burger|Turkey Cheeseburger Whole Wheat Bun
"menu": {
"items": [
"Turkey Burger",
"Turkey Cheeseburger Whole Wheat Bun
"Crisp Sweet Potato Waffle Fries (VE)",
"Baked Beans (VE)",
],
},
}, {
"dateStr": "September 6; 2023?Wednesday ",
"date": {
"type": "date",
"date": "2023-09-06T00:00:00.000Z",
"prefix": "September 6; 2023",
"suffix": "Wednesday ",
},
"menuStr":
"{Caribbean Style Beef Patty |Callaloo Spinach (V)}",
"menu": {
"items": [
"Caribbean Style Beef Patty ",
"Callaloo Spinach (V)",
],
},
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
export const DOEMenuTypes = {
"High-School-Express-Cold-Lunch-Menu": {
title: "High School Express Cold Lunch",
},
"high-school-express-hot-lunch-menu": {
title: "High School Express Hot Lunch",
},
"high-school-lunch-menu": {
title: "High School Lunch",
},
"Infant-Toddler-Lunch-Menu": {
title: "Infant Toddler Lunch Menu",
},
"j-h-s-middle-school-lunch-menu": {
title: "JHS and Middle School Lunch",
},
"Pre-K---8-Express-Cold-Lunch-Menu": {
title: "Pre-K–8 Express Cold Lunch",
},
"pre-k---8-express-hot-lunch-menu": {
title: "Pre-K–8 Express Hot Lunch",
},
"pre-k---8-lunch-menu": {
title: "Pre-K–8 Lunch",
},
"Puree-Lunch-Menu": {
title: "Puree Lunch",
},
"saturday-cold-lunch-menu": {
title: "Saturday Cold Lunch",
},
"saturday-hot-lunch-menu": {
title: "Saturday Hot Lunch",
},
"pre-k---8-vegetarian-lunch-menu": {
title: "Pre-K-8 Vegitarian Lunch",
},
} as const;
1
2
3
4
5
6
7
8
9
10
11
12
import { parseMenuLine } from "https://esm.town/v/tal/parseMenuLine";
import { fetchDOEMenu } from "https://esm.town/v/tal/fetchDOEMenu";
export const testDoeMenuLines = (async () => {
const menuText = await fetchDOEMenu({
schoolYear: "2023-2024",
month: "september",
menuType: "pre-k---8-lunch-menu",
});
const lines = menuText.split("\r\n").map(parseMenuLine);
return lines;
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fetch } from "https://esm.town/v/std/fetch";
// https://www.schools.nyc.gov/docs/default-source/school-menus/2023-2024/september/pre-k---8-express-hot-lunch-menu
//
export let fetchDOEMenu: (opts: {schoolYear: `${number}-${number}`, month: string, menuType: string}) = (async ({schoolYear, month, menuType}) => {
const resp = await fetch(
`https://www.schools.nyc.gov/docs/default-source/school-menus/${schoolYear}/${month}/${menuType}`,
{
},
);
if (resp.status !== 200) {
console.log("status: ", resp.status)
console.log("status: ", resp.statusText)
console.log("type: ", resp.type)
console.log("headers: ", resp.headers)
console.log("keys: ", resp.headers.keys)
}
return resp.text();
});
Next