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;' 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)) r = db_engine.execute(text(query))
meals = [] meals = []
for row in r: for row in r:
meals.append(dict(row)) meals.append(dict(row))
r.close() 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 return meals
@app.route('/') @app.route('/')
def index(): def index():
print (getUpcomingMeals())
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), current_user_name='Wille') return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), current_user_name='Wille')
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save