Skip to content

Commit

Permalink
Added calorie information, meal timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mertatilgan committed May 23, 2024
1 parent c76afe5 commit 9cec951
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 18 deletions.
14 changes: 10 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def parse_menu(xml_string):
yemekler = gun.find('yemekler')
meals = [clean_meal_name(yemek.text.strip())
for yemek in yemekler.findall('yemek')]
meals_by_date[tarih] = meals
kalori = gun.find('kalori').text.strip()
meals_by_date[tarih] = {"meals": meals, "calories": kalori}

return meals_by_date

Expand Down Expand Up @@ -63,16 +64,21 @@ def index():
else:
meals_dict["date"] = f"{day_name} Gününün Menüsü ({formatted_date})"

meals_dict["meals"] = meals_data[formatted_date]
meals_dict["meals"] = meals_data[formatted_date]["meals"]
meals_dict["calories"] = meals_data[formatted_date]["calories"]
meals_list.append(meals_dict)

elif date_to_check.strftime("%-d.%m.%Y") in meals_data:
formatted_date = date_to_check.strftime("%-d.%m.%Y")
meals_list.append(
{"date": f"{day_name}, {formatted_date}", "meals": meals_data[formatted_date]})
{"date": f"{day_name}, {formatted_date}",
"meals": meals_data[formatted_date]["meals"],
"calories": meals_data[formatted_date]["calories"]})
else:
meals_list.append(
{"date": f"{day_name}, {formatted_date}", "meals": ["Yemek bulunamadı."]})
{"date": f"{day_name}, {formatted_date}",
"meals": ["Yemek bulunamadı."],
"calories": "N/A"})

return render_template('meals.html', meals=meals_list)

Expand Down
63 changes: 63 additions & 0 deletions static/mealtimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const mealTimesWeekday = [
{ start: "08:00", end: "09:15" },
{ start: "11:30", end: "14:00" },
{ start: "17:00", end: "19:00" }
];

const mealTimesWeekend = [
{ start: "09:00", end: "10:00" },
{ start: "12:00", end: "13:30" },
{ start: "17:00", end: "19:00" }
];

function getMealTimes() {
const now = new Date();
const day = now.getDay();
return (day === 0 || day === 6) ? mealTimesWeekend : mealTimesWeekday;
}

function timeStringToDate(timeString) {
const now = new Date();
const [hours, minutes] = timeString.split(":").map(Number);
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes);
}

function updateTimer() {
const now = new Date();
const mealTimes = getMealTimes();
let nextMeal = null;
let message = "";

for (const mealTime of mealTimes) {
const start = timeStringToDate(mealTime.start);
const end = timeStringToDate(mealTime.end);

if (now >= start && now <= end) {
message = "Şu an yemek zamanı!";
break;
} else if (now < start) {
nextMeal = start;
break;
}
}

if (!message) {
if (nextMeal) {
const diff = nextMeal - now;
const hours = Math.floor(diff / 1000 / 60 / 60);
const minutes = Math.floor((diff / 1000 / 60) % 60);
if (hours > 0) {
message = `Bir sonraki yemek <strong>${hours} saat ${minutes} dakika</strong> sonra.`;
} else {
message = `Bir sonraki yemek <strong>${minutes} dakika</strong> sonra.`;
}
} else {
message = "Bugün için yemek saati bitti.";
}
}

document.getElementById("timer").innerHTML = `${message} <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>`;
}

setInterval(updateTimer, 1000);
updateTimer();
20 changes: 20 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,24 @@
li {
font-size: 20px;
list-style-type: disc !important;
}

.line {
border-top: 2px dashed;
}

.line.active {
border-top: 2px dashed #fff;
}

.timer {
text-align: center;
font-size: 1.5rem;
margin-top: 20px;
}

.alert-danger {
background-color: #e20a16;
border-color: #c90a15;
color: #fff;
}
50 changes: 36 additions & 14 deletions templates/meals.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,33 @@

<body>
<div class="container">
<br>
<div class="alert alert-danger alert-dismissible fade show" role="alert" id="timer">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<ul class="list-group mt-4">
{% for meal in meals %}
<li class="list-group-item {% if loop.index0 == 0 %}active{% endif %}">
<h3 class="mb-3">{{ meal.date }}</h2>
<ul>
{% for m in meal.meals %}
<li>{{ m }}</li>
{% endfor %}
</ul>
<h3 class="mb-3">{{ meal.date }}</h3>
<ul>
{% for m in meal.meals %}
<li>{{ m }}</li>
{% endfor %}
</ul>
<hr class="line {% if loop.index0 == 0 %}.active{% endif %}">
<p>
<small>
Toplam Kalori: <strong>{{ meal.calories }} kcal</strong>
</small>
</p>
</li><br>
{% endfor %}
</ul>

<div class="row">
<div class="col-sm-6">
<div class="col-sm-6 mb-4 mb-sm-0">
<div class="card text-center">
<div class="card-header">
<h5>Hafta İçi Yemek Saatleri</h5>
Expand All @@ -38,10 +50,11 @@ <h5>Hafta İçi Yemek Saatleri</h5>
</ul>
</div>
</div>

<div class="col-sm-6">
<div class="card text-center">
<div class="card-header">
<h5>Hafta Sonu (ve tatil günleri) Yemek Saatleri</h5>
<h5>Hafta Sonu Yemek Saatleri</h5>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">09.00 – 10.00</li>
Expand All @@ -51,18 +64,27 @@ <h5>Hafta Sonu (ve tatil günleri) Yemek Saatleri</h5>
</div>
</div>
</div>

<footer class="py-3 my-4">
<p class="text-center text-muted">Made with ❤ by <a href="https://github.com/mertatilgan" class="me">Mert
Kemal Atılgan</a></p>
<p class="text-center text-muted">Bread Icon created by <a href="https://www.flaticon.com/free-icons/bread"
title="bread icons" class="me">Freepik - Flaticon</a></p>
<p class="text-center text-muted">
<strong>Not: </strong> Verilerin girişinde üniversiteden kaynaklı olarak bazı yemeklerin
detayları gösterilmeyebilir.
</p>
<hr>
<p class="text-center text-muted">
<a href=" https://github.com/mertatilgan" class="me">Mert Kemal Atılgan</a> tarafından ❤ ile yapıldı.
</p>
<p class="text-center text-muted">
Ekmek ikonu <a href="https://www.flaticon.com/free-icons/bread" title="bread icons" class="me">Freepik -
Flaticon</a>'dan.
</p>

</footer>
</div>

<script src="{{url_for('static', filename='mealtimer.js')}}"></script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
</body>

</html>
</html>

0 comments on commit 9cec951

Please sign in to comment.