Last active
August 8, 2025 15:07
-
-
Save pyrodex/aeffbf250920f107a40890eeae5f762b to your computer and use it in GitHub Desktop.
Simple python code to pull Meal Viewer daily menu and write it to an HTML file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
from datetime import datetime | |
from datetime import timedelta | |
lunch_file = "/apps/swag/config/www/lunch_entrees.html" | |
# Get today's date | |
date = datetime.now() + timedelta(days=1) | |
# Get the day of the week name | |
day_of_week = date.strftime("%A") | |
# Check if it's a weekday (Monday = 0, ..., Friday = 4) | |
if date.weekday() < 5: # 0 to 4 are weekdays | |
# Format the date as MM-DD-YYYY | |
formatted_date = date.strftime("%m-%d-%Y") | |
url = f"https://api.mealviewer.com/api/v4/school/SharonElementary/{formatted_date}/{formatted_date}/0" | |
#print(url) | |
# Make the GET request | |
response = requests.get(url) | |
data = response.json() # Parse the JSON response | |
# Extract lunch entrees | |
lunch_entrees = [] | |
html_content = "" | |
menu_blocks = data.get('menuSchedules', [{}])[0].get('menuBlocks', []) | |
if menu_blocks: | |
for entry in data['menuSchedules'][0]['menuBlocks'][1]['cafeteriaLineList']['data'][0]['foodItemList']['data']: | |
lunch_entrees.append(entry['item_Type'] + " - " + entry['item_Name']) | |
# Create HTML content | |
html_content = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Lunch - Sharon Elementary</title> | |
<style> | |
body { font-size: 1.2em; font-family: Arial, sans-serif; margin: 20px; } | |
h3 { color: #F4F5F0; } | |
ul { color: #F4F5F0; list-style-type: square; } | |
</style> | |
</head> | |
<body> | |
<h3>Lunch for """ | |
html_content += day_of_week + " (" + formatted_date + "):" | |
html_content += """</h3> | |
<ul> | |
""" | |
for entree in lunch_entrees: | |
html_content += f" <li>{entree}</li>\n" | |
html_content += """ | |
</ul> | |
</body> | |
</html> | |
""" | |
else: | |
html_content = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Lunch - Sharon Elementary</title> | |
<style> | |
body { font-size: 1.2em; font-family: Arial, sans-serif; margin: 20px; } | |
h3 { color: #F4F5F0; } | |
ul { color: #F4F5F0; list-style-type: square; } | |
</style> | |
</head> | |
<body> | |
<h3>No Lunch for """ | |
html_content += day_of_week + " (" + formatted_date + "):" | |
html_content += """ Missing menu blocks, usually because there is no menu.</h3> | |
</body> | |
</html> | |
""" | |
# Save HTML to a file | |
with open(lunch_file, "w") as file: | |
file.write(html_content) | |
else: | |
formatted_date = date.strftime("%m-%d-%Y") | |
html_content = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Lunch - Sharon Elementary</title> | |
<style> | |
body { font-size: 1.2em; font-family: Arial, sans-serif; margin: 20px; } | |
h3 { color: #F4F5F0; } | |
ul { color: #F4F5F0; list-style-type: square; } | |
</style> | |
</head> | |
<body> | |
<h3>No Lunch for """ | |
html_content += day_of_week + " (" + formatted_date + "):" | |
html_content += """ since its a weekend!</h3> | |
</body> | |
</html> | |
""" | |
# Save HTML to a file | |
with open(lunch_file, "w") as file: | |
file.write(html_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment