commit 9a74569d4c3203a4ac19193010eb6f32b5e7032d
Author: jc <419690370@qq.com>
Date: Mon Mar 17 22:44:37 2025 +0800
first commit
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..2c20395
--- /dev/null
+++ b/app.py
@@ -0,0 +1,42 @@
+from flask import Flask, jsonify, send_from_directory
+
+app = Flask(__name__, static_folder="public", static_url_path="")
+
+
+# 根路径返回 index.html
+@app.route("/")
+def serve_index():
+ return send_from_directory(app.static_folder, "index.html")
+
+
+# API 子路径,提供减肥计划数据
+@app.route("/api/weight-loss-plan")
+def weight_loss_plan():
+ plan = {
+ "message": "Welcome to the Weight Loss Plan",
+ "plan": {
+ "week1": {
+ "monday": {"meal": "Salad with grilled chicken", "calories": 300},
+ "tuesday": {"meal": "Veggie stir-fry with tofu", "calories": 250},
+ "wednesday": {"meal": "Quinoa salad", "calories": 350},
+ "thursday": {"meal": "Grilled fish with steamed vegetables", "calories": 400},
+ "friday": {"meal": "Lentil soup", "calories": 300},
+ "saturday": {"meal": "Greek yogurt with berries", "calories": 200},
+ "sunday": {"meal": "Baked sweet potato with cottage cheese", "calories": 350}
+ },
+ "week2": {
+ "monday": {"meal": "Oatmeal with almond milk", "calories": 300},
+ "tuesday": {"meal": "Chicken breast with broccoli", "calories": 350},
+ "wednesday": {"meal": "Chickpea salad", "calories": 300},
+ "thursday": {"meal": "Turkey burger with lettuce wrap", "calories": 400},
+ "friday": {"meal": "Vegetable sushi rolls", "calories": 250},
+ "saturday": {"meal": "Smoothie with spinach and banana", "calories": 200},
+ "sunday": {"meal": "Egg white omelette with avocado", "calories": 300}
+ }
+ }
+ }
+ return jsonify(plan)
+
+
+if __name__ == "__main__":
+ app.run(debug=True,host="0.0.0.0", port=80)
\ No newline at end of file
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..cb4b86d
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+ Weight Loss Plan
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/script.js b/public/script.js
new file mode 100644
index 0000000..afe6ace
--- /dev/null
+++ b/public/script.js
@@ -0,0 +1,33 @@
+document.addEventListener("DOMContentLoaded", () => {
+ fetch("/api/weight-loss-plan")
+ .then(response => response.json())
+ .then(data => {
+ const week1 = document.getElementById("plan-week1");
+ const week2 = document.getElementById("plan-week2");
+
+ const renderPlan = (week, weekData) => {
+ const days = Object.keys(weekData);
+ days.forEach(day => {
+ const meal = weekData[day];
+ const dayDiv = document.createElement("div");
+ dayDiv.classList.add("day");
+
+ const dayHeader = document.createElement("h3");
+ dayHeader.textContent = `${day.charAt(0).toUpperCase() + day.slice(1)}`;
+ dayDiv.appendChild(dayHeader);
+
+ const mealInfo = document.createElement("p");
+ mealInfo.textContent = `Meal: ${meal.meal} (Calories: ${meal.calories})`;
+ dayDiv.appendChild(mealInfo);
+
+ week.appendChild(dayDiv);
+ });
+ };
+
+ renderPlan(week1, data.plan.week1);
+ renderPlan(week2, data.plan.week2);
+ })
+ .catch(error => {
+ console.error("Error fetching data:", error);
+ });
+});
\ No newline at end of file
diff --git a/public/styles.css b/public/styles.css
new file mode 100644
index 0000000..4e52768
--- /dev/null
+++ b/public/styles.css
@@ -0,0 +1,42 @@
+body {
+ font-family: Arial, sans-serif;
+ background-color: #f4f4f4;
+ margin: 0;
+ padding: 0;
+}
+
+.container {
+ max-width: 800px;
+ margin: 20px auto;
+ padding: 20px;
+ background: white;
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
+ border-radius: 8px;
+}
+
+h1, h2 {
+ text-align: center;
+ color: #333;
+}
+
+#plan-container {
+ margin-top: 20px;
+}
+
+.day {
+ background: #e9f2ff;
+ padding: 10px;
+ margin-bottom: 10px;
+ border-radius: 5px;
+}
+
+.day h3 {
+ margin: 0 0 5px;
+ color: #007bff;
+}
+
+.day p {
+ margin: 0;
+ font-size: 14px;
+ color: #555;
+}
\ No newline at end of file