Skip to content

Commit

Permalink
Add MealViewer (#2884)
Browse files Browse the repository at this point in the history
* Add MealViewer

* remove debug

* use http cache instead of cache module

* run linter
  • Loading branch information
jed authored Nov 24, 2024
1 parent 37da427 commit 1016f59
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/mealviewer/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
id: mealviewer
name: MealViewer
summary: MealViewer Next Lunch
desc: Shows the next school day lunch entree from MealViewer.
author: Jed Schmidt
fileName: mealviewer.star
packageName: mealviewer
90 changes: 90 additions & 0 deletions apps/mealviewer/mealviewer.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
load("http.star", "http")
load("render.star", "render")
load("schema.star", "schema")
load("time.star", "time")

def get_next_lunch(school_name):
start = time.now()
end = start + time.parse_duration("%sh" % 24 * 7)

url = "https://api.mealviewer.com/api/v4/school/{}/{}/{}/0".format(
school_name,
start.format("01-02-2006"),
end.format("01-02-2006"),
)

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}

response = http.get(url, headers = headers, ttl_seconds = 3600)
data = response.json()

num_schedules = len(data["menuSchedules"])

if (num_schedules == 0):
return "ERROR", "Invalid school ID"

for i in range(num_schedules):
if i == 0 and start.hour >= 12:
pass
else:
schedule = data["menuSchedules"][i]
title = "LUNCH TODAY" if i == 0 else "LUNCH TOMORROW" if i == 1 else "LUNCH " + schedule["dateInformation"]["weekDayName"].upper()
if (len(schedule["menuBlocks"]) >= 2):
lunch = schedule["menuBlocks"][1]["cafeteriaLineList"]["data"][0]["foodItemList"]["data"][0]
name = lunch["item_Name"] if lunch["item_Type"] == "Entrée" else lunch["item_Type"]
return title, name

return "NEXT LUNCH", "No upcoming lunch"

def main(config):
school_name = config.get("school_id", "KingstonCitySchoolDistrictElementarySchools")

title, name = get_next_lunch(school_name)

return render.Root(
child = render.Column(
expanded = True,
main_align = "start",
children = [
render.Box(
width = 64,
height = 7,
color = "#7f2629",
child = render.Padding(
pad = (0, 2, 0, 0),
child = render.Text(
title,
color = "#000000",
font = "tom-thumb",
),
),
),
render.Box(
child = render.WrappedText(
name,
color = "#ADD8E6",
width = 64,
align = "center",
font = "tb-8",
),
),
],
),
)

def get_schema():
return schema.Schema(
version = "1",
fields = [
schema.Text(
id = "school_id",
name = "School MealViewer ID",
desc = "The ID of your school, the last part of your MealViewer URL",
icon = "gear",
default = "KingstonCitySchoolDistrictElementarySchools",
),
],
)

0 comments on commit 1016f59

Please sign in to comment.