From a24d7932872baf1a068ca77aeb91d42cf5ae36d3 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Fri, 30 Nov 2018 21:54:49 +0100 Subject: [PATCH] Some fixes and additions --- kukv1.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kukv1.py b/kukv1.py index e66cca8..f509346 100644 --- a/kukv1.py +++ b/kukv1.py @@ -49,14 +49,19 @@ def getUpcomingMeals(): meals = [] for row in r: meals.append(dict(row)) - seconds_to_deadline = (parse(meals[-1]['selection_deadline']) - datetime.datetime.now()).seconds + print (meals) + print ('deadline ' + str(meals[-1]['selection_deadline'] )) + seconds_to_deadline = (meals[-1]['selection_deadline'] - datetime.datetime.now()).total_seconds() + print(str(seconds_to_deadline) + ' s to dead') 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 + elif seconds_to_deadline > 3600: + hours_td = round(seconds_to_deadline / 3600) + days_td = int(hours_td / 24) hours_td = hours_td % 24 - meals[-1]['selection_deadline'] = str(days_td) + ' days ' + str(hours_td) + meals[-1]['selection_deadline'] = str(days_td) + ' days ' + str(hours_td) + ' hours' + else: + meals[-1]['selection_deadline'] = str(round(seconds_to_deadline / 60)) + ' minutes' r.close() return meals