Calculating friendly timedelta string

master
Davide Bongiovanni 6 years ago
parent 056de43a91
commit 0f6b449bf0

@ -36,13 +36,22 @@ def getUpcomingMeals():
query = 'select username as kuk, meal_date, array_agg as eaters, selection_deadline from (select kuk, meal_date, selection_deadline, array_agg(username) from meals join users on users.id = any(meals.eaters) where meals.status=0 group by meals.id order by meal_date) as foo join users on kuk=users.id;'
r = db_engine.execute(text(query))
meals = []
for row in r:
meals.append(dict(row))
r.close()
for row in r:
meals.append(dict(row))
seconds_to_deadline = (parse(meals[-1]['selection_deadline']) - datetime.datetime.now()).seconds
if seconds_to_deadline < 0:
meals[-1]['selection_deadline'] = 'Deadline passed'
else:
hours_td = round(seconds_to_deadline / 60 / 60)
days_td = hours_td / 24
hours_td = hours_td % 24
meals[-1]['selection_deadline'] = str(days_td) + ' days ' + str(hours_td)
r.close()
return meals
@app.route('/')
def index():
print (getUpcomingMeals())
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), current_user_name='Wille')
if __name__ == '__main__':

Loading…
Cancel
Save